Upgrade audio_session to handle willPauseWhenDucked correctly on Android.
This commit is contained in:
parent
1a1424a45b
commit
de7da29ed6
|
@ -14,7 +14,7 @@ packages:
|
|||
name: audio_session
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.5"
|
||||
version: "0.0.7"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -113,7 +113,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.4.2"
|
||||
version: "0.4.3"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -6,7 +6,7 @@ environment:
|
|||
sdk: ">=2.7.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
audio_session: ^0.0.5
|
||||
audio_session: ^0.0.7
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
|
|
|
@ -115,49 +115,6 @@ class AudioPlayer {
|
|||
androidAudioSessionId: data['androidAudioSessionId'],
|
||||
);
|
||||
//print("created event object with state: ${_playbackEvent.state}");
|
||||
if (handleInterruptions) {
|
||||
AudioSession.instance.then((session) {
|
||||
session.becomingNoisyEventStream.listen((_) {
|
||||
pause();
|
||||
});
|
||||
session.interruptionEventStream.listen((event) {
|
||||
if (event.begin) {
|
||||
switch (event.type) {
|
||||
case AudioInterruptionType.duck:
|
||||
if (session.androidAudioAttributes.usage ==
|
||||
AndroidAudioUsage.game) {
|
||||
setVolume(volume / 2);
|
||||
}
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
case AudioInterruptionType.pause:
|
||||
case AudioInterruptionType.unknown:
|
||||
if (playing) {
|
||||
pause();
|
||||
// Although pause is async and sets _playInterrupted = false,
|
||||
// this is done in the sync portion.
|
||||
_playInterrupted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (event.type) {
|
||||
case AudioInterruptionType.duck:
|
||||
setVolume(min(1.0, volume * 2));
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
case AudioInterruptionType.pause:
|
||||
if (_playInterrupted) play();
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
case AudioInterruptionType.unknown:
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return _playbackEvent;
|
||||
} catch (e, stacktrace) {
|
||||
print("Error parsing event: $e");
|
||||
|
@ -216,6 +173,49 @@ class AudioPlayer {
|
|||
.distinct()
|
||||
.listen(setAndroidAudioAttributes);
|
||||
});
|
||||
if (handleInterruptions) {
|
||||
AudioSession.instance.then((session) {
|
||||
session.becomingNoisyEventStream.listen((_) {
|
||||
pause();
|
||||
});
|
||||
session.interruptionEventStream.listen((event) {
|
||||
if (event.begin) {
|
||||
switch (event.type) {
|
||||
case AudioInterruptionType.duck:
|
||||
if (session.androidAudioAttributes.usage ==
|
||||
AndroidAudioUsage.game) {
|
||||
setVolume(volume / 2);
|
||||
}
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
case AudioInterruptionType.pause:
|
||||
case AudioInterruptionType.unknown:
|
||||
if (playing) {
|
||||
pause();
|
||||
// Although pause is async and sets _playInterrupted = false,
|
||||
// this is done in the sync portion.
|
||||
_playInterrupted = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (event.type) {
|
||||
case AudioInterruptionType.duck:
|
||||
setVolume(min(1.0, volume * 2));
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
case AudioInterruptionType.pause:
|
||||
if (_playInterrupted) play();
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
case AudioInterruptionType.unknown:
|
||||
_playInterrupted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// The latest [PlaybackEvent].
|
||||
|
|
|
@ -14,7 +14,7 @@ packages:
|
|||
name: audio_session
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.5"
|
||||
version: "0.0.7"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -8,7 +8,7 @@ environment:
|
|||
flutter: ">=1.12.13+hotfix.5"
|
||||
|
||||
dependencies:
|
||||
audio_session: ^0.0.5
|
||||
audio_session: ^0.0.7
|
||||
rxdart: ^0.24.1
|
||||
path: ^1.6.4
|
||||
path_provider: ^1.6.10
|
||||
|
|
Loading…
Reference in New Issue