Youtube player view in iOS

#pragma mark - UIWebViewFactory

+ (UIWebView *)youtubePlayerViewWithFrame:(CGRect)frame andURLString:(NSString *)URLString {
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    videoView.backgroundColor = [UIColor clearColor];
    videoView.opaque = NO;
    
    NSString *videoHTML = [NSString stringWithFormat:@"\
                           <html>\
                           <head>\
                           <style type=\"text/css\">\
                           iframe {position:absolute; top:0; margin-top:0px;}\
                           body {background-color:#000; margin:0;}\
                           </style>\
                           </head>\
                           <body>\
                           <iframe width=\"%0.0f\" height=\"%0.0f\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
                           </body>\
                           </html>", frame.size.width, frame.size.height, [ACMUtility youtubeEmbededURLStringFromURLString:URLString]];
    
    [videoView loadHTMLString:videoHTML baseURL:nil];
    
    return videoView;

}


How to call this method:

                UIWebView *videoView = [CommonClass youtubePlayerViewWithFrame:view.bounds andURLString:attrib.source];
                videoView.tag = 2;
                [view addSubview:videoView];

Comments

Popular posts from this blog

Exception Handling - Objective C

Vector graphics in iOS

How to show activity indicator in watch kit