Configure AndroidAudioAttributes from audio_session.
This commit is contained in:
parent
09eb73be34
commit
c1716cbb3b
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.3.3"
|
||||
version: "0.3.4"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -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()]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue