Post not yet marked as solved
Post marked as unsolved with 0 replies, 306 views
basically i'm having two modes for my application first one play application music and second one play music of application as well as other application.....when i switch between them some times it is confuse and not able to play correct musicdo { 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)") }