繁体   English   中英

使用MPMoviePlayerViewController在iPhone模拟器上播放视频

[英]Playing Video on iPhone simulator with MPMoviePlayerViewController

我正在使用MPMoviePlayerViewController播放视频。 我添加了以下代码,但是没有播放。 视图以黑屏显示,并且立即隐藏而不播放。

 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];

我需要做更多的事情来播放mp4文件吗?注意:我正在模拟器中尝试。 是否可以在模拟器中播放(.mp4)文件。

我使用了MPMoviePlayerController而不是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];

试试这个,这应该工作。

试试这个代码:),我想它只支持.mov文件,而您的视频无法播放,因为它的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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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