簡體   English   中英

MPMoviePlayerViewController立即關閉

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM