如何恢复正在使用presentMoviePlayerViewControllerAnimated播放的电影 [英] How to resume a movie that's being played with presentMoviePlayerViewControllerAnimated

查看:106
本文介绍了如何恢复正在使用presentMoviePlayerViewControllerAnimated播放的电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码来显示电影:

I'm uisng this code to display a movie:

 MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]
 initWithContentURL:movieURL];
 mp.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
 [self presentMoviePlayerViewControllerAnimated:mp]; [mp.moviePlayer play];

代码工作正常。但是,当应用程序在播放电影时进入后台时,当应用程序返回到前台时,不会显示电影播放器​​。 (我看到控制器的视图叫 presentMoviePlayerViewControllerAnimated:mp

The code is working fine. However when the application goes to the background while playing a movie, when the app comes back in the foreground the movieplayer is not displayed. (I see the view of the controller that called presentMoviePlayerViewControllerAnimated:mp

进入foregound是否可以恢复在应用程序进入后台之前播放的电影?

Is it possible when entering the foregound to resume the movie that was playing before the app went to the background?

推荐答案

您可以实施通知技术来处理它。添加通知在电影播放器​​正在播放的类中,并将其与选择器相关联。当应用程序转到后台时,然后在委托方法中

you can implement notification techniques to handle it. Add a notification in the class where movie player is playing and associate with it a selector. When app goes to background then in the delegate method

- (void)applicationDidEnterBackground:(UIApplication *)application

{

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 

 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.


    UIApplication *app = [UIApplication sharedApplication];
    UIBackgroundTaskIdentifier bgTask = 0;

    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
    }];

}

编写此代码。实际上,当应用程序进入后台时,它会暂停MPMoviePlayerController所以当它到达前台时,你发布通知,该通知在实现电影控制器的类中调用该方法,并在此方法中再次播放。

write this code.Actually when app goes background it pauses the MPMoviePlayerController so when it is coming to foreground you post the notification which call the method in class where movie controller is implemented and play it again in this method.

-(void)playIntroAnimationAgain

{

[[NSNotificationCenter defaultCenter]removeObserver:self name:NOTIFICATION_PlayAgain_Player object:nil];

        [self.moviePlayerController play];

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playIntroAnimationAgain)name:NOTIFICATION_PlayAgain_Player object:nil];
}

它解决了我的问题。

这篇关于如何恢复正在使用presentMoviePlayerViewControllerAnimated播放的电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆