2012-10-23 220 views
1

我想用MPMoviePlayerViewController播放視頻。所以在我的視圖控制器中,我註冊爲MPMoviePlayerLoadStateDidChangeNotification的觀察者。MPMoviePlayerLoadStateDidChangeNotification適用於iOS 5,但不適用於iOS 6

我再初始化MPMoviePlayerViewController:

self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"<videoURL>"]]; 

,並等待通知到達。當它執行此代碼時:

MPMoviePlayerController* playerController = notification.object; 

if ([playerController loadState] & MPMovieLoadStatePlayable) { 
    if (self.mPlayerVC) { 
     [self presentMoviePlayerViewControllerAnimated:self.mPlayerVC]; 
    } 
} 

任何人都知道爲什麼這適用於iOS 5但不適用於iOS 6?謝謝

回答

2

似乎有iOS 6的MediaPlayer.framework中的錯誤。要初始化的MPMoviePlayerViewController

self.mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"<videoURL>"]]; 
[self.mPlayerVC.moviePlayer prepareToPlay]; 

後獲得視頻播放我打電話prepareToPlay現在通知再次進來,但應用程序崩潰時我打電話[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC];在被稱爲該MPMoviePlayerLoadStateDidChangeNotification的方法。

,防止死機更換

[self presentMoviePlayerViewControllerAnimated:self.mPlayerVC]; 

的東西,如

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) { 
[self presentViewController:self.mPlayerVC animated:YES completion:nil]; 
} 
else if ([self respondsToSelector:@selector(presentModalViewController:animated:)]) { 
[self presentModalViewController:self.mPlayerVC animated:YES]; 
} 
相關問題