[英]Playing Video on iPhone simulator with MPMoviePlayerViewController
I am using MPMoviePlayerViewController to play video. 我正在使用MPMoviePlayerViewController播放视频。 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. 我需要做更多的事情来播放mp4文件吗?注意:我正在模拟器中尝试。 Is it possible to play a (.mp4) file in Simulator.
是否可以在模拟器中播放(.mp4)文件。
I have used MPMoviePlayerController instead of MPMoviePlayerViewController: 我使用了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];
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 试试这个代码:),我想它只支持.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.