【问题标题】:Play audio in background in ios 7在 ios 7 中在后台播放音频
【发布时间】:2014-08-11 09:37:39
【问题描述】:

我使用本指南为我的应用制作了音频播放器 http://www.ymc.ch/en/building-a-simple-audioplayer-in-ios

我面临的问题是当手机被锁定时音频停止,而当铃声关闭时音频变为静音。 有人可以指导我如何在手机锁定的情况下继续播放音频。

【问题讨论】:

    标签: objective-c ios7


    【解决方案1】:

    首先你必须将必需的后台模式设置为应用播放音频

    并在 AppDelegate.m 的 didFinishLaunching 方法中编写以下代码

     NSError *setCategoryErr = nil;
     NSError *activationErr  = nil;
     [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
     [[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
    

    iOS background audio not playing

    【讨论】:

    • 非常感谢您的回复。现在,当应用程序进入后台时,音频不会暂停。如何实现控制中心中的暂停和播放按钮,需要更多帮助。
    • 您必须转到您的应用程序并以编程方式暂停音频,或者当手机锁定的暂停按钮将出现在屏幕上时。您可以使用该暂停按钮来暂停音频。
    猜你喜欢
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多