Use Apple native video player MPMoviePlayerController to play videos from Youku and other web pages

Source: Internet
Author: User

Without its own streaming media server, and want to use the native video player MPMoviePlayerController in the app to insert video into the interface, the interface can be played directly, or full-screen playback, can be achieved by the following methods

Create a native player first

   _movieplayer = [[MPMoviePlayerController alloc] init];   _movieplayer.controlstyle = mpmoviecontrolstyleembedded;   _movieplayer.shouldautoplay = NO;   _movieplayer.view.frame = CGRectMake (0, 0, hx_screen_width, +);           [Self.scrollview Addsubview:_movieplayer.view];

then request Youku and other video pages to load the data

   Nsurl *fileurl = [Nsurl urlwithstring:<span style= "Background-color:rgb (240, 240, 240);" >@ "You want to extract streaming address Youku and other pages" </span>];   Nsurlrequest *request = [Nsurlrequest requestwithurl:fileurl];           UIWebView *webview = [[UIWebView alloc]init];   Webview.delegate = self;   [WebView Loadrequest:request];

Then by implementing the UIWebView delegate method:

#pragma mark-uiwebviewdelegate-(void) Webviewdidfinishload: (UIWebView *) webview{    nsstring *ljs = @ " Document.documentElement.innerHTML ";    NSString *lhtml = [WebView Stringbyevaluatingjavascriptfromstring:ljs];    NSLog (@ "HTML content:%@", lhtml);//above is just printing information for reference, the following is the extract stream        //NSString *LJS2 = @ "(document.getElementsByTagName (\" video \ ") [0]). getElementsByTagName (\" source\ ") [0].SRC];  Qiyi    NSString *ljs2 = @ "(document.getElementsByTagName (\" video\ ") [0]). src";  Youku,tudou,ku6, Souhu    nsstring *lm3u8 = [WebView stringbyevaluatingjavascriptfromstring:ljs2];    NSLog (@ "video source:%@", lm3u8);    load to native player play    nsurl *movieurl = [Nsurl urlwithstring:lm3u8];    _movieplayer.contenturl = Movieurl;    [_movieplayer Preparetoplay];}

Description: WebView to add to your view, otherwise it is never going to load the request;



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use Apple native video player MPMoviePlayerController to play videos from Youku and other web pages

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.