我正在使用iOS 6中包含的mediaplayer框架嘗試從應用內播放電影。我導入,然後:iOS中播放視頻的媒體播放器框架6
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
當調用此函數時,視圖會變爲空白屏幕和無限加載。我已經嘗試過許多其他版本的這個實現,結果各不相同,都失敗了。在特定情況下的日誌是:
2012-11-05 21:19:27.900 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.902 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.977 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.978 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.984 [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-11-05 21:19:28.156 [MPAVController] Autoplay: Enabling autoplay
想了解原因?這是我第一次嘗試播放視頻,現在它已成爲一場噩夢。
嘗試調用'[moviePlayerController prepareToPlay];' –
添加了[moviePlayerController prepareToPlay],但是這並沒有改變結果。 – AddisDev
請參考http://stackoverflow.com/questions/11549143/playing-a-downloaded-video-from-the-documents-directory-with-cocoa-touch –