Mpmovieplayerviewcontroller for simple MP4 playback

Source: Internet
Author: User

1. To use mpmovieplayerviewcontroller, you must first add mediaplayer. framework.
2. Add the following code:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad {    [super viewDidLoad];    NSString *url = [[NSBundle mainBundle] pathForResource:@"TaylorSwift-LoveStory" ofType:@"mp4"];        MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:)                                                 name:MPMoviePlayerPlaybackDidFinishNotification                                               object:[playerViewController moviePlayer]];    //-- add to view---    [self.view addSubview:playerViewController.view];        //---play movie---    MPMoviePlayerController *player = [playerViewController moviePlayer];    [player play];    }- (void) movieFinishedCallback:(NSNotification*) aNotification {    MPMoviePlayerController *player = [aNotification object];    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];    [player stop];    [self.view removeFromSuperView];    [player autorelease];}

3. The shouldautorotatetointerfaceorientation: interfaceorientation method can be modified on a horizontal screen to return YES.

Note: The above method can be used to directly play the locally m3u8 format or online video.

 

Nsurl can be directly initialized:

Nsurl * videopathurl = [nsurl urlwithstring: urlstr]; // urlstr is the video playback address.

For playing a local video. Initialize as follows:

Nsurl * videopathurl = [[nsurl alloc] initfileurlwithpath: urlstr];

 

Turn: http://re-reference.iteye.com/blog/1106324

Mpmovieplayerviewcontroller for simple MP4 playback

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.