继续在后台播放MPMoviePlayerViewController中的电影 [英] Continue playing movie in MPMoviePlayerViewController in background

查看:102
本文介绍了继续在后台播放MPMoviePlayerViewController中的电影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MPMoviePlayerViewController在我的应用程序中播放电影。

I have an MPMoviePlayerViewController that plays a movie in my app.

启用多任务处理以便我可以返回主屏幕或锁定设备然后使用音乐控件继续播放音频。问题是当应用程序失去焦点时音频停止,因此您必须手动按播放才能再次启动它。

Multitasking is enabled so that I can return to the home screen or lock the device and then use the music controls to continue playing audio. The problem is the fact that audio is stopped when the app loses focus, so that you have to manually press play to start it again.

默认音乐应用程序,当然和其他一些如Ambiance继续在后台播放音频但是这些只播放音频,而我的应用程序的音频源是视频 - 是否可以在从MPMoviePlayerViewController失去焦点时继续播放?

The default music app, of course, and some others such as Ambiance continue playing audio in the background however these only ever play audio whereas my app's audio source is a video - is it possible to keep playing when losing focus from a MPMoviePlayerViewController?

推荐答案

这对我有用。
按下视频播放器完成按钮时加载错误的网址。
例如

This works for me. Load a false url when video player done button pressed. For Example

 [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:yourViewController];

并实施

- (void)moviePlaybackComplete:(NSNotification *)notification
{
    self.playerViewController=[self.playerViewController initWithContentURL:[NSURL URLWithString:@"dummyUrl"]];
    [self.playerViewController.moviePlayer stop];
    MPMoviePlayerViewController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerController];
}

这很好用。
谢谢

This works just fine. Thanks

这篇关于继续在后台播放MPMoviePlayerViewController中的电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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