简体   繁体   中英

Playing Video on iPhone simulator with MPMoviePlayerViewController

I am using MPMoviePlayerViewController to play video. I have added following piece of code, However its not playing. View is presenting with black screen and hiding immediately without playing.

 MPMoviePlayerViewController  *moviePlayerVC = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:@"/Users/gui_test/Desktop/273_0.mp4"]];
    moviePlayerVC.moviePlayer.allowsAirPlay = YES; 
    moviePlayerVC.view.backgroundColor = [UIColor blackColor];
    [self presentMoviePlayerViewControllerAnimated:moviePlayerVC];
    [moviePlayerVC.moviePlayer play];

Am I need to do anything more to play a mp4 file Note: I am trying in simulator. Is it possible to play a (.mp4) file in Simulator.

I have used MPMoviePlayerController instead of MPMoviePlayerViewController:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:songUrl];
[[self.moviePlayer view] setBounds:CGRectMake(0, 0, 320, 480)];
[moviePlayer.backgroundView setBackgroundColor:[UIColor blackColor]];   
moviePlayer.controlStyle = MPMovieControlStyleDefault;
[moviePlayer setScalingMode:MPMovieScalingModeNone];
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:NO];

Try this this should work.

Try this code :) , and I guess it supports .mov files only and your video isn't playing cause its mp4

NSString*thePath=[[NSBundle mainBundle] pathForResource:@"filename" ofType:@"mov"];
NSURL*theurl=[NSURL fileURLWithPath:thePath];
NSLog(@"the url= %@",theurl);

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:theurl];
[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 480)];
[moviePlayer prepareToPlay];
[moviePlayer setFullscreen:YES];
[moviePlayer setShouldAutoplay:YES]; 
[self.view addSubview:moviePlayer.view];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM