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

查看:34
本文介绍了如何恢复正在使用 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

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

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天全站免登陆