Play youtube video in iOS app

Youtube video can be played in iOS app using webview. MPMoviePlayerController is not able to open youtube video automatically. Integrate the below script to show thumbnail, clicking on it the video will play in full screen.


    NSString *url = @"https://www.youtube.com/embed/8aMHGC6A5zc";
    
    NSString* embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <iframe id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\" frameborder=\"0\" feature=player_detailpage allowfullscreen></iframe>\
    </body></html>";
    
    NSString* html = [NSString stringWithFormat:embedHTML, url, self.view.frame.size.width, 200.0];

    [webview loadHTMLString:html baseURL:nil];

Comments

Popular posts from this blog

Exception Handling - Objective C

Vector graphics in iOS

How to show activity indicator in watch kit