ryanheise / audio_session

MIT License
117 stars 82 forks source link

interruptionEventStream doesn't emit a new item when TalkBack is on (Android) #48

Closed aednlaxer closed 2 years ago

aednlaxer commented 2 years ago

It seems that interruptionEventStream doesn't emit a new interruption event when certain conditions are met:

Reproduction path:

Observed behavior:

When changing focus the app doesn't receive a new AudioInterruptionEvent. This makes it impossible to do necessary changes in the audio playback (pause playback etc). The app is unable to update playback state (I'm using this plugin along with audio_service). There's playback state mismatch: app shows that playback is ongoing although it's actually not.

Expected behavior:

App gets notified about new audio interruption via AudioSession.interruptionEventStream.

My audio session configuration:

final config = const AudioSessionConfiguration.speech()
    .copyWith(androidWillPauseWhenDucked: true);
ryanheise commented 2 years ago

Can you point to any other audio apps that correctly handle the interruption?

aednlaxer commented 2 years ago

After further investigation I can say it's not a bug of this plugin 🙂 I've checked Spotify, Youtube and Google Podcasts apps with ducking off and all these apps continue playback while TalkBack is in use. I'm using text to speech plugin along with audio_service and audio_session. Turns out TalkBack with ducking off stops TTS engine's playback directly but doesn't do anything with media players and their audio focus\session. TTS plugin I'm using receives a stop\interruption event but audio service and audio session don't and this is not an issue of this plugin but rather how things work on Android with that setting off.

ryanheise commented 2 years ago

That doesn't surprise me, Android considers TTS and music as different kinds of audio streams which is also why I provide that hack in audio_service to force the media buttons to show by playing a little bit of "real" audio (or what Android considers real audio. TTS doesn't count, since it's on it's own special audio stream.) Anyway, that's not exactly the same issue here, TalkBack could have been programmed to request audio focus if they wanted it to, but I guess the fact that they didn't is consistent with their overall approach to treat TTS output differently from normal audio output.