gpt4 book ai didi

ios5 - iOS5 中的 MPMoviePlayerController 后台音频问题

转载 作者:行者123 更新时间:2023-12-04 15:03:06 26 4
gpt4 key购买 nike

我有一个执行非常标准操作的应用程序:
当应用程序处于 1) 前台模式,2) 屏幕锁定状态 3) 后台模式时,它会播放音频(流式传输或在文件系统中)。
这在 iOS5 之前的所有 iOS 中都运行良好。

我一直在使用 MPMoviePlayerController (因为它可以播放流媒体和本地文件系统音频)
我有以下设置:

  • info.plist 将背景模式设置为“音频”
  • 我有 Audiosession 设置,如 http://developer.apple.com/library/ios/#qa/qa1668/_index.html 所示
    NSError *activationError = nil;
    AVAudioSession *mySession = [AVAudioSession sharedInstance];
    [mySession setCategory: AVAudioSessionCategoryPlayback error: &activationError];
    if (activationError) { /* handle the error condition */ }
    [mySession setActive: YES error: &activationError];
    if (activationError) { /* handle the error condition */ }
  • 我启用了在音频播放结束时停止的后台计时器
    UIBackgroundTaskIdentifier newId = [[UIApplication sharedApplication]
    beginBackgroundTaskWithExpirationHandler:NULL];
  • 我有 Moveplayer 的 useApplicationAudioSession = NO
  • 我订阅了以下事件来检测和处理各种播放状态并在当前文件的末尾启动一个新的音频文件。
    MPMoviePlayerLoadStateDidChangeNotification
    MPMoviePlayerPlaybackDidFinishNotification
    MPMoviePlayerPlaybackStateDidChangeNotification
    MPMoviePlayerNowPlayingMovieDidChangeNotification

  • 问题:

    这样音频开始播放,当应用程序进入后台状态或手机被锁定时,音频继续播放。但是,当我开始另一个音频文件后,
    我立即开始收到 PlaybackDidFinishNotification 状态设置为播放结束(但文件从未播放过)

    同样的代码在前台模式播放音频文件(当前音频文件结束后,下一个文件开始没有问题)

    iOS5 中有什么新东西我应该做才能让它工作吗?我通读了 MPMoviePlayerController 类引用,但看不到任何特定于 iOS5 的内容。

    提前致谢。

    最佳答案

    终于想通了这个问题。这是在 this 中解决的在苹果开发论坛发帖(需要登录才能看到)。该帖子适用于 AVPlayer,但也解决了 MPMoviePlayerController 的问题。

    基本上,这是该帖子的摘录:

    your app must support remote control events! These are the audio controller interface prex/nex/play/pause on the left of the multitask switcher taskbar (not sure about the proper name of the thing). You to this ensuring your view becomes First Controller and then calling


    > [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    in viewDidLoad. Once you do this, your Player will no longer return NO!!

    关于ios5 - iOS5 中的 MPMoviePlayerController 后台音频问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8161165/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com