【发布时间】:2015-07-06 20:30:57
【问题描述】:
我正在编写一个播放音乐的应用程序。但是,我想让我的应用程序的音乐在其他音乐播放时暂停,例如来自 iTunes 的音乐。我将如何做到这一点?这是我的代码:
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Ambler", ofType: "mp3")!)
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
audioPlayer.numberOfLoops = -1
【问题讨论】:
标签: ios swift avfoundation avaudioplayer