【问题标题】:Xcode: Play an audio file with music on the backgroundXcode:播放背景音乐的音频文件
【发布时间】:2014-12-20 08:57:08
【问题描述】:

我使用 Cordova 3.6.3 构建了一个使用界面声音的 iOS 应用程序。当您单击按钮时,应用程序会播放短促的“点击”声。这很好用。但是,当我在另一个应用程序的背景上播放音乐时使用我的应用程序时,会发生这种情况: 1. 背景音乐淡出。 2.播放界面声音。 3. 背景音乐淡入。

这不应该发生。我想在背景音乐仍在播放时播放界面声音。我需要对 Cordova / Phonegap 进行什么更改才能更改此行为?与 AVAudioSession 有关吗?

感谢您的帮助。

【问题讨论】:

    标签: ios objective-c xcode cordova


    【解决方案1】:

    我在 CDVSound.m 中找到了解决方案。

    旧版本

    NSString* sessionCategory = bPlayAudioWhenScreenIsLocked ? AVAudioSessionCategoryPlayback : AVAudioSessionCategorySoloAmbient;
    [self.avSession setCategory:sessionCategory error:&err];
    

    新版本

    NSString* sessionCategory = bPlayAudioWhenScreenIsLocked ? AVAudioSessionCategoryAmbient : AVAudioSessionCategoryAmbient;
    [self.avSession setCategory:sessionCategory error:&err];
    

    查看https://developer.apple.com/Library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionBasics/AudioSessionBasics.html了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      相关资源
      最近更新 更多