func playSpawnedDot() { var alertSound: NSURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("spawnDot",ofType: "mp3")!)! var error:NSError? audioPlayer = AVAudioPlayer(contentsOfURL: alertSound,error: &error) audioPlayer.preparetoPlay() if volumeBool { audioPlayer.play() }}解决方法 您需要设置AVAudioSession类别,具有以下值之一: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html(AVAudioSession类参考).
默认值设置为AVAudioSessioncategorySoloAmbIEnt.如你所见:
[…] using this category implIEs that your app’s audio is nonmixable—activating your session will interrupt any other audio sessions which are also nonmixable. To allow mixing,use the
AVAudioSessioncategoryAmbIEnt
category instead.
在播放声音之前,您必须更改该类别.这样做:
AVAudioSession.sharedInstance().setcategory(AVAudioSessioncategoryAmbIEnt,error: nil)AVAudioSession.sharedInstance().setActive(true,error: nil)
每次播放声音时都不需要调用这些行.你可能只想做一次.
总结以上是内存溢出为你收集整理的ios – 在使用Swift时,我的应用仍然播放声音时,如何允许背景音乐继续播放全部内容,希望文章能够帮你解决ios – 在使用Swift时,我的应用仍然播放声音时,如何允许背景音乐继续播放所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)