mapbox-navigation-ios icon indicating copy to clipboard operation
mapbox-navigation-ios copied to clipboard

Music from some apps stops playing when my step by step navigation app starts

Open hastiranjkesh opened this issue 8 years ago • 2 comments

I want audio from my app (a voice in a turn-by-turn navigation app) to be heard over music or other currently playing audio. My app’s audio is occasional and spoken. I'm having issues with some applications like Telegram, WhatsApp, Slack. Music from these apps stops playing when my app starts. This is my code: In RouteVoiceController class:

func duckAudio() throws {
var categoryOptions: AVAudioSessionCategoryOptions = [.duckOthers, .interruptSpokenAudioAndMixWithOthers, .allowBluetooth, .defaultToSpeaker]
try AVAudioSession.sharedInstance().setMode(AVAudioSessionModeSpokenAudio)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: categoryOptions)  
try AVAudioSession.sharedInstance().setActive(true)
}

func unDuckAudio() throws {
try AVAudioSession.sharedInstance().setActive(false, with: [.notifyOthersOnDeactivation])
}

It works fine with Apple Music, Spotify, and SoundCloud apps but It stops Telegram, WhatsApp, Slack player. I also have these warnings in the console when my audio starts playing. I am using iOS12.1, XCode Version 10.1 :

[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)

Mapbox Navigation SDK version: 0.22

hastiranjkesh avatar Dec 03 '18 08:12 hastiranjkesh

@hastiranjkesh was this issue resolved, or closed for some other reason?

jim-martin avatar Dec 19 '18 19:12 jim-martin

@jim-martin It was my fault, I replaced AVAudioSessionCategoryPlayAndRecord with AVAudioSessionCategoryPlayback and removed allowBluetooth from category options and It resolved.

hastiranjkesh avatar Dec 22 '18 08:12 hastiranjkesh