0

我正在使用 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) 文件。

4

2 回答 2

0

试试这个代码:),我猜它只支持 .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];
于 2012-12-27T16:52:36.260 回答
0

我使用了 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];

试试这个应该可以。

于 2012-09-03T06:58:27.343 回答