你可以使用這段代碼來阻止控制器播放在播放結(jié)束后自動(dòng)dismissing(消失),并且捕捉到用戶點(diǎn)擊完成的按鈕事件去自己定義并處理讓你的MPMoviePlayerViewController播放器的消失(dismiss)的時(shí)機(jī)
步驟 1. - 創(chuàng)建并初始化一個(gè)MPMoviePlayerViewController(videoPlayer)
MPMoviePlayerViewController *videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[[NSURL alloc ]initWithString:[aURL];
步驟 2. - 移除videoPlayer默認(rèn)的通知事件并且加入自己的通知事件。
[[NSNotificationCenter defaultCenter] removeObserver:videoPlayer
name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer];
步驟 3. - 手動(dòng)顯示你的videoPlayer控制器
[self presentMoviePlayerViewControllerAnimated:videoPlayer];
步驟 4. - 添加 videoFinish: 方法處理通知事件
-(void)videoFinished:(NSNotification*)aNotification{
int value = [[aNotification.userInfo valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (value == MPMovieFinishReasonUserExited) {
[self dismissMoviePlayerViewControllerAnimated];
}
}