Configure AndroidAudioAttributes from audio_session.

This commit is contained in:
Ryan Heise 2020-08-22 13:44:51 +10:00
parent 09eb73be34
commit c1716cbb3b
3 changed files with 12 additions and 2 deletions

View File

@ -553,11 +553,12 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
}
private void setAudioAttributes(Map<?, ?> json) {
ensurePlayerInitialized();
AudioAttributes.Builder builder = new AudioAttributes.Builder();
builder.setContentType((Integer)json.get("contentType"));
builder.setFlags((Integer)json.get("flags"));
builder.setUsage((Integer)json.get("usage"));
builder.setAllowedCapturePolicy((Integer)json.get("allowedCapturePolicy"));
//builder.setAllowedCapturePolicy((Integer)json.get("allowedCapturePolicy"));
player.setAudioAttributes(builder.build());
}

View File

@ -113,7 +113,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.3"
version: "0.3.4"
matcher:
dependency: transitive
description:

View File

@ -200,6 +200,14 @@ class AudioPlayer {
onError: _playbackEventSubject.addError,
);
_sequenceSubject.add(null);
// Respond to changes to AndroidAudioAttributes configuration.
AudioSession.instance.then((audioSession) {
audioSession.configurationStream
.map((conf) => conf?.androidAudioAttributes)
.where((attributes) => attributes != null)
.distinct()
.listen(setAndroidAudioAttributes);
});
}
/// The latest [PlaybackEvent].
@ -636,6 +644,7 @@ class AudioPlayer {
/// platforms. This will cause a new Android AudioSession ID to be generated.
Future<void> setAndroidAudioAttributes(
AndroidAudioAttributes audioAttributes) async {
if (audioAttributes == null) return;
await _invokeMethod(
'setAndroidAudioAttributes', [audioAttributes.toJson()]);
}