[英]MPMoviePlayerViewController dismisses immediately
我正在通過以下方式播放電影:
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];
//[[vc moviePlayer] prepareToPlay];
[self presentViewController:moviePlayer animated:YES completion:NULL];
控制器顯示出來,但之后立即解散。 我究竟做錯了什么? 謝謝!
您必須像這樣刪除MPMoviePlayerPlaybackDidFinishNotification
NSNotificationCenter
:
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];
//[[vc moviePlayer] prepareToPlay];
[[NSNotificationCenter defaultCenter] removeObserver:moviePlayer name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer.moviePlayer];
[self presentViewController:moviePlayer animated:YES completion:NULL];
因為MPMoviePlayerViewController
在創建后會自動將其注冊到NSNotificationCenter
。 您必須先刪除此注冊,它會停止自動退出。 希望它對您有幫助
請檢查波紋管鏈接:-
http://josebolanos.wordpress.com/2011/09/28/dismissing-mpmovieplayerviewcontroller-the-right-way/
嘗試播放音頻時遇到了類似的問題。 嘗試將電影播放器設置為具有強參考性的屬性。
檢查您的-(void)viewWillDisappear:(BOOL)animated{
方法,如果您要dismissing
moviePlayer
那么這就是原因。
從文檔:
“要以模態方式顯示電影播放器視圖控制器,通常使用presentMoviePlayerViewControllerAnimated:
方法。此方法是UIViewController
類的類別的一部分,由Media Player框架實現presentMoviePlayerViewControllerAnimated:
方法使用以下presentMoviePlayerViewControllerAnimated:
呈現電影播放器視圖控制器:用於呈現視頻內容的標准過渡動畫。要關閉以模態呈現的電影播放器視圖控制器,請調用dismissMoviePlayerViewControllerAnimated
方法。
您不能使用常規的模態表示方法。 必須使用UIViewContoller
類別中的媒體播放器框架提供的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.