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
|
name: audio_session
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.0.5"
|
version: "0.0.7"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -113,7 +113,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.4.2"
|
version: "0.4.3"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -6,7 +6,7 @@ environment:
|
||||||
sdk: ">=2.7.0 <3.0.0"
|
sdk: ">=2.7.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
audio_session: ^0.0.5
|
audio_session: ^0.0.7
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
|
|
|
@ -115,49 +115,6 @@ class AudioPlayer {
|
||||||
androidAudioSessionId: data['androidAudioSessionId'],
|
androidAudioSessionId: data['androidAudioSessionId'],
|
||||||
);
|
);
|
||||||
//print("created event object with state: ${_playbackEvent.state}");
|
//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;
|
return _playbackEvent;
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
print("Error parsing event: $e");
|
print("Error parsing event: $e");
|
||||||
|
@ -216,6 +173,49 @@ class AudioPlayer {
|
||||||
.distinct()
|
.distinct()
|
||||||
.listen(setAndroidAudioAttributes);
|
.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].
|
/// The latest [PlaybackEvent].
|
||||||
|
|
|
@ -14,7 +14,7 @@ packages:
|
||||||
name: audio_session
|
name: audio_session
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.0.5"
|
version: "0.0.7"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -8,7 +8,7 @@ environment:
|
||||||
flutter: ">=1.12.13+hotfix.5"
|
flutter: ">=1.12.13+hotfix.5"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
audio_session: ^0.0.5
|
audio_session: ^0.0.7
|
||||||
rxdart: ^0.24.1
|
rxdart: ^0.24.1
|
||||||
path: ^1.6.4
|
path: ^1.6.4
|
||||||
path_provider: ^1.6.10
|
path_provider: ^1.6.10
|
||||||
|
|
Loading…
Reference in New Issue