【问题标题】:IOS13 Audio Issue when App sends to background and back to foreground应用程序发送到后台并返回到前台时的IOS13音频问题
【发布时间】:2020-07-09 01:27:03
【问题描述】:

在 iOS 13 中,当我将 SceneKit 应用程序发送到后台并返回前台时,播放音频时出现问题。

以下代码可以很好地在将应用程序发送到后台之前播放 AudioSource。

var hitSound: SCNAudioSource!
hitSound = SCNAudioSource(named: "hitSound.mp3")!
hitSound = false
rootNode.runAction(SCNAction.playAudio(hitSound, waitForCompletion: false))

当我将应用程序发送到后台时,下面的控制台中出现了以下警告。

[avae]     AVAEInternal.h:109   [AVAudioEngineGraph.mm:1544:Start: (err = PerformCommand(*ioNode, kAUStartIO, NULL, 0)): error 561015905

此外,当应用程序回到前台时,会发生以下警告并停止播放 SCNAudioSource 声音。在 iOS 12 中,不会出现这样的问题。

[avae]     AVAEInternal.h:76    required condition is false: [AVAudioPlayerNode.mm:712:ScheduleBuffer: (_outputFormat.channelCount == buffer.format.channelCount)]

【问题讨论】:

  • 您的 AVAudioSession 在类别、激活和中断方面做了什么?
  • AVSounds 正在播放声音。这只发生在 scnaudiosources 上。
  • 好的,所以您不愿意回答问题?这很难提供帮助。
  • 我的意思是我使用 AVAudioPlayer 播放菜单声音并使用 scnAudioSource 播放游戏音效。我在菜单中没有 AVAudioPlayer 播放声音的问题,但游戏声音完全变为静音,并且游戏中的每次碰撞,我都收到“AVAEInternal.h:76”错误。我还没有定义 AVAudioSession
  • "我还没有定义 AVAudioSession" 好了,问题就在这里。

标签: swift scenekit avaudioplayer


【解决方案1】:

我在 Signing & Capabilities 下启用 Audio in Background Modes 并将以下代码添加到 didFinishLaunchingWithOptions 下的 AppDelegate 中后,问题已解决。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

    // Get the singleton instance.
    let audioSession = AVAudioSession.sharedInstance()
    do {
        // Set the audio session category, mode, and options.
        try audioSession.setCategory(.playback, mode: .moviePlayback, options: [])
    } catch {
        print("Failed to set audio session category.")
    } 
    return true
}

【讨论】:

  • 不需要在后台模式下启用音频,但上面的代码有效。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
  • 2011-05-22
相关资源
最近更新 更多