MPMoviePlayerController 在 ios5 屏幕锁定期间无法播放

发布于 2024-12-11 19:59:03 字数 743 浏览 0 评论 0原文

我的应用程序使用 MPMoviePlayerController 来播放播客。在ios4中,我能够使用以下代码绕过锁屏停止播放播客:

OSStatus audioInitStat = AudioSessionInitialize (NULL,NULL,NULL,NULL);
if (audioInitStat != kAudioSessionNoError) {
    printf("AudioSession Failed to Initialize\n");
}
else {
    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    audioInitStat = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,    sizeof(sessionCategory), &sessionCategory);
}

以前它能工作可能是运气不好,但事实是,现在随着ios5的引入,电影播放器​​停止了ios4 中没有屏幕锁定。有谁知道如何让电影播放器​​在屏幕锁定期间播放。我不想使用:

[[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ];

因为这只会耗尽电池(即我想让屏幕变暗)。任何想法将不胜感激。如果我无法使用电影播放器​​,你知道我是否可以使用ios的任何其他音频功能来播放播客?

My app used the MPMoviePlayerController to play podcasts. In ios4, I was able to circumvent the lock-screen halting the play of podcasts with the following code:

OSStatus audioInitStat = AudioSessionInitialize (NULL,NULL,NULL,NULL);
if (audioInitStat != kAudioSessionNoError) {
    printf("AudioSession Failed to Initialize\n");
}
else {
    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    audioInitStat = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,    sizeof(sessionCategory), &sessionCategory);
}

It may have been dumb luck that it worked before, but the fact is that now with the introduction of ios5, the movie player stops with screen lock when it did not in ios4. Does anyone know how to allow the movie player to play during screen-lock. I do not want to use:

[[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ];

because that will just kill the battery (i.e. I want to allow the screen to dim). Any ideas would be most appreciated. If I can't use the movie player, do you know if I can use any other audio capabilities of ios to play podcasts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月打碎记忆 2024-12-18 19:59:04

在 iOS 5.x 中,您需要在 info.plist 文件中设置两个键。

首先向文件中添加一行,键为“UIApplicationExitsOnSuspend”,将该值设置为布尔值并将其设置为“NO”,

然后添加一行,键名为“UIBackgroundModes”
这将是一个数组,您希望第一个项目的值为“音频”。

您可能还想将音频会话设置为 AVAudioSessionCategoryPlayback 以进行良好的测量:

    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

这适用于使用 MPMoviePlayerController 播放的音频文件,但不适用于视频。

In iOS 5.x you need to set two keys in your info.plist file.

First add a row to the file with the Key "UIApplicationExitsOnSuspend" make the value a Boolean and set it to "NO"

Next add a row with a key named "UIBackgroundModes"
This will be an Array and you want the first item to have a value of "audio"

You might also want to set your audio session to AVAudioSessionCategoryPlayback for good measure:

    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

This will work for audio files played back using MPMoviePlayerController but not video.

霊感 2024-12-18 19:59:04

经过大量挖掘,我找到了部分解决方案:

转到您的应用程序的 info.plist。

添加键“所需的背景模式”并将值设置为“应用程序播放音频”
添加键“应用程序在后台运行”并将值设置为“是”

我不知道这在哪里记录,但它有效。

这只是部分解决方案。这样,音频可以在后台播放,但您无法按主页按钮访问其他应用程序。当您按下主页按钮时,该应用程序将终止。

After much digging, I found a partial solution:

Go to your info.plist for your app.

Add the key 'Required background modes' and set the value to 'App plays audio'
Add the key 'Application does run in background' and set the value to 'YES'

I have no idea where this is documented, but it works.

This is only a partial solution. With this, audio can play in the background, but you can't press the home button to access other apps. The app will terminate when you press the Home button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文