How to play youtube/vimeo video within the application in iPhone

前端 未结 9 2169
[愿得一人]
[愿得一人] 2020-12-23 02:42

I am building an application where I want to play video from url like Youtube, Vimeo, Direct url. I am making custom player using AVPlayer to play a video from a direct url

相关标签:
9条回答
  • 2020-12-23 03:14

    For Vimeo player you can check this link https://github.com/lilfaf/YTVimeoExtractor it plays the video in real player and if you want to run the video in uiwebview,here is the code for that https://stackoverflow.com/a/15918011/1865424.

    Pass you URL of YouTube Video in “urlStr”.

    //In .h file
    UIWebView *videoView;
    // In .m file
    
    videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 385)];
    
    [self embedYouTube :urlStr  frame:CGRectMake(0, 0, 320, 385)];
    
    [self.view addSubview:videoView];
    
    // methos to embed URL in HTML & load it to UIWebView
    
    - (void)embedYouTube:(NSString*)url frame:(CGRect)frame
    
    {
    
    NSString* embedHTML = @”\
    
    <html><head>\
    
    <style type=\”text/css\”>\
    
    body {\
    
    background-color: transparent;\
    
    color: white;\
    
    }\
    
    </style>\
    
    </head><body style=\”margin:0\”>\
    
    <embed id=\”yt\” src=\”%@\” type=\”application/x-shockwave-flash\” \
    
    width=\”%0.0f\” height=\”%0.0f\”></embed>\
    
    </body></html>”;
    
    
    
    NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
    
    if(videoView == nil) {
    
    videoView = [[UIWebView alloc] initWithFrame:frame];
    
    [self.view addSubview:videoView];
    
    }
    
    [videoView loadHTMLString:html baseURL:nil];
    
    }
    

    Courtsey :- http://nanostuffs.com/Blog/?p=641

    Hope This Will Help You Out. If this doesn't help you out please check out these links:-

    http://blog.softwareispoetry.com/2010/03/how-to-play-youtube-videos-in-your.html

    https://gist.github.com/darkredz/5334409

    http://maniacdev.com/2012/02/open-source-library-for-easily-playing-a-youtube-video-in-an-mpmovieplayer

    0 讨论(0)
  • 2020-12-23 03:18

    Use this

    NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1] ;
    [html appendString:@"<html><head>"];
    [html appendString:@"<style type=\"text/css\">"];
    [html appendString:@"body {"];
    [html appendString:@"background-color: transparent;"];
    [html appendString:@"color: white;"];
    [html appendString:@"}"];
    [html appendString:@"</style>"];
    [html appendString:@"</head><body style=\"margin:0\">"];
    [html appendString:@"<iframe src=\"//player.vimeo.com/video/84403700?autoplay=1&amp;loop=1\" width=\"1024\" height=\"768\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"];
    [html appendString:@"</body></html>"];
    
    
    [viewWeb loadHTMLString:html baseURL:urlMovie];
    
    0 讨论(0)
  • 2020-12-23 03:20

    enter image description hereenter image description here

    I've used this class just for that.

    The video you see inside the UIViewController is playable in its current size.

    That's the only code I've used:

    UIView *videoContainerView = [[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 200)];
        [self.view addSubview:videoContainerView];        
        XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"_OBlgSz8sSM"];
        [videoPlayerViewController presentInView:videoContainerView];
        [videoPlayerViewController.moviePlayer play];
    
    0 讨论(0)
提交回复
热议问题