Skip to content

Commit

Permalink
fix: audio resumes after a phone call even if it was paused before #926
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 24, 2024
1 parent 9bd16e0 commit fd1899f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdkVersion 33
compileSdkVersion 34

ndkVersion "21.4.7075529"

Expand Down
17 changes: 13 additions & 4 deletions lib/services/audio_services/mobile_audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class MobileAudioService extends BaseAudioHandler {
AudioSession.instance.then((s) {
session = s;
session?.configure(const AudioSessionConfiguration.music());

bool wasPausedByBeginEvent = false;

s.interruptionEventStream.listen((event) async {
if (event.begin) {
switch (event.type) {
Expand All @@ -25,17 +28,23 @@ class MobileAudioService extends BaseAudioHandler {
break;
case AudioInterruptionType.pause:
case AudioInterruptionType.unknown:
await audioPlayer.pause();
break;
{
wasPausedByBeginEvent = audioPlayer.isPlaying;
await audioPlayer.pause();
break;
}
}
} else {
switch (event.type) {
case AudioInterruptionType.duck:
await audioPlayer.setVolume(1.0);
break;
case AudioInterruptionType.pause:
case AudioInterruptionType.unknown:
case AudioInterruptionType.pause when wasPausedByBeginEvent:
case AudioInterruptionType.unknown when wasPausedByBeginEvent:
await audioPlayer.resume();
wasPausedByBeginEvent = false;
break;
default:
break;
}
}
Expand Down

0 comments on commit fd1899f

Please sign in to comment.