MPMoviePlayerController loadState不会切换到MPMovieLoadStatePlayable

时间:2012-09-24 14:31:02

标签: iphone video mpmovieplayercontroller

我有一个MPMoviePlayerViewController来全屏播放电影。我通过Quicktime检查了他们播放的电影。 问题是,使用MPMoviePlayerViewController(模拟器和设备)电影无法开始播放(这是一个本地存储在iPad上的视频)。

NSString *path = [[NSBundle mainBundle]pathForResource:resource ofType:@"mov"];
self.mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];
[self.mpviewController.moviePlayer prepareToPlay];
self.mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.mpviewController.moviePlayer.controlStyle = [self presentModalViewController:self.mpviewController animated:YES];

NSLog(@"%d",self.mpviewController.moviePlayer.loadState);

[self.mpviewController.moviePlayer play];

任何想法我错过了什么?

TIA

1 个答案:

答案 0 :(得分:0)

好吧,我不知道它是什么。我最后用这段代码编写了一个新的视图控制器 - 它起作用了:

NSURL *url = [NSURL fileURLWithPath:self.urlPath];

self.playerController = [[MPMoviePlayerController alloc] initWithContentURL: url];
CGRect bounds = CGRectMake(0, 0, 1024, 748);
self.playerController.scalingMode = MPMovieScalingModeNone;

[self.playerController.view setFrame:bounds];

[self.view addSubview:self.playerController.view];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerDidExitFullscreenCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:self.playerController];

self.playerController.controlStyle = MPMovieControlStyleFullscreen;
[self.playerController setFullscreen:YES animated:YES];
[self.playerController play];