基本上,我的应用程序有两种模式:第一种播放应用程序音乐,第二种播放应用程序音乐以及其他应用程序...在它们之间切换时,无法播放正确的音乐有时:
Common.fs
Workflow1\Impl1.fs
Workflow2\Impl2.fs
有时它会显示类似错误
do {
if sound > 1 {
// 1st mode play with app sound
if !FromStart {
print("sound > 1", self.audioEngine.isRunning)
self.audioEngine.stop()
self.audioEngine.reset()
try AVAudioSession.sharedInstance().setActive(false)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
// sleep(1)
//try self.audioEngine.start()
do {
// 3
try self.audioEngine.start()
} catch let error {
print("error sound > 1",error.localizedDescription)
}
if !FromStart {
self.PlayNewButtonSound()
}
}
} else if sound > 0 {
//2nd mode play with other app sound
if !FromStart {
self.audioEngine.stop()
}
//print("sound > 0", self.audioEngine.isRunning)
try AVAudioSession.sharedInstance().setActive(false)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
//try self.audioEngine.start()
do {
// 3
try self.audioEngine.start()
} catch let error {
print("error > 0",error.localizedDescription)
}
self.skHomesound?.run(SKAction.stop())
if !FromStart {
self.PlayNewButtonSound()
}
}
} catch {
print("Problem with enable sound error = \(error.localizedDescription)")
}