我正在開發一個需要使用Xcode 4.5.2和iOS 6.0播放視頻的應用程序。MPMoviePlayer控制器不播放視頻
我正在使用MPMoviePlayerController來播放視頻。我遵循this tutorial。但是,我仍然無法在模擬器中播放視頻。
這裏是我的代碼:
- (IBAction)playVideo:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Movie-1" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
moviePlayerController.shouldAutoplay =YES ;
moviePlayerController.controlStyle = MPMovieControlStyleDefault ;
moviePlayerController.scalingMode = MPMovieScalingModeFill ;
[moviePlayerController.view setFrame:CGRectMake(0, 0, 360, 200)];
[self.view addSubview:moviePlayerController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController play ] ;
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}
我已經看了很多做題,但它們都沒有解決我的問題。我還試圖創建一個containerView並將我的MPMoviePlayerController
添加到我的containerView中。我沒有讓它工作。我也試過MPMoviePlayerViewController
,到目前爲止我能夠使它工作。它的另一個問題,我不能setFrame
到MPMoviePlayerViewController
。但是,我想將幀設置爲我的視頻播放器。它的大小不可能是全屏。因爲我需要在我的視頻播放器下方顯示一些按鈕。
你們有什麼想法,我該如何做到這一點?
編輯:控制檯輸出
2012-12-19 16:29:21.554 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:21.555 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:21.565 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:27.230 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:27.231 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:27.241 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:27.706 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:27.707 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:27.718 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:27.919 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:27.920 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:27.930 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.077 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.077 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.088 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.219 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.220 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.230 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.368 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.368 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.382 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.511 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.512 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.521 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.692 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.692 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.702 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
add [moviePlayerController prepareToPlay];之前[moviePlayerController播放];如果它不工作檢查文件的路徑 –
我已經嘗試了prepareToPlay方法,它沒有效果,只是兩次控制檯輸出。文件的路徑也是正確的。 – limon