应用启动ios后,背景音乐停止播放 [英] background device music gets stopped as app starts ios

查看:422
本文介绍了应用启动ios后,背景音乐停止播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用iPhone播放音乐,当我运行我的应用程序时,它不应停止后台设备音乐,而应该停止自己的音乐,而背景音乐将停止.我想做糖果粉碎应用程序.我应该怎么做才能解决这个问题?请帮助我

I am playing music in iphone and when I run my application it should not stop background device music and should stop its own music instead background music is getting stop. I want to do same as candy crush app. What should I do to resolve this? Please help me

    var isOtherAudioPlaying = AVAudioSession.sharedInstance().otherAudioPlaying
      println("isOtherAudioPlaying>>> \(isOtherAudioPlaying)")
      if(isOtherAudioPlaying == false)
           {
            audioPlayer1!.play()
           }

推荐答案

我建议您查看 Sameer对于Swift 2.0的回答,几个月前.与Swift 2.0完美配合.

I would suggest checking out Sameer's answer to this for Swift 2.0, just a few months back. Works perfectly with Swift 2.0.

let sess = AVAudioSession.sharedInstance()
if sess.otherAudioPlaying {
    _ = try? sess.setCategory(AVAudioSessionCategoryAmbient, withOptions: []) //
    _ = try? sess.setActive(true, withOptions: [])
}

这篇关于应用启动ios后,背景音乐停止播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆