Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 589fbe8

Browse files
committed
Android Support mixWithOthers configuration
1 parent 42d95b3 commit 589fbe8

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

packages/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ final class VideoPlayer {
5757

5858
private boolean isInitialized = false;
5959

60+
private final VideoPlayerOptions options;
61+
6062
VideoPlayer(
6163
Context context,
6264
EventChannel eventChannel,
6365
TextureRegistry.SurfaceTextureEntry textureEntry,
6466
String dataSource,
6567
Result result,
66-
String formatHint) {
68+
String formatHint,
69+
VideoPlayerOptions options) {
6770
this.eventChannel = eventChannel;
6871
this.textureEntry = textureEntry;
72+
this.options = options;
6973

7074
TrackSelector trackSelector = new DefaultTrackSelector();
7175
exoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
@@ -165,7 +169,7 @@ public void onCancel(Object o) {
165169

166170
surface = new Surface(textureEntry.surfaceTexture());
167171
exoPlayer.setVideoSurface(surface);
168-
setAudioAttributes(exoPlayer);
172+
setAudioAttributes(exoPlayer, options.mixWithOthers);
169173

170174
exoPlayer.addListener(
171175
new EventListener() {
@@ -209,10 +213,10 @@ void sendBufferingUpdate() {
209213
}
210214

211215
@SuppressWarnings("deprecation")
212-
private static void setAudioAttributes(SimpleExoPlayer exoPlayer) {
216+
private static void setAudioAttributes(SimpleExoPlayer exoPlayer, boolean isMixMode) {
213217
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
214218
exoPlayer.setAudioAttributes(
215-
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build());
219+
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), !isMixMode);
216220
} else {
217221
exoPlayer.setAudioStreamType(C.STREAM_TYPE_MUSIC);
218222
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.flutter.plugins.videoplayer;
2+
3+
public class VideoPlayerOptions {
4+
public VideoPlayerOptions(boolean mixWithOthers) {
5+
this.mixWithOthers = mixWithOthers;
6+
}
7+
8+
public final boolean mixWithOthers;
9+
}

packages/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class VideoPlayerPlugin implements MethodCallHandler, FlutterPlugin {
2323
private static final String TAG = "VideoPlayerPlugin";
2424
private final LongSparseArray<VideoPlayer> videoPlayers = new LongSparseArray<>();
2525
private FlutterState flutterState;
26+
private boolean mixWithOthers = true;
2627

2728
/** Register this with the v2 embedding for the plugin to respond to lifecycle callbacks. */
2829
public VideoPlayerPlugin() {}
@@ -95,6 +96,12 @@ public void onMethodCall(MethodCall call, Result result) {
9596
case "init":
9697
disposeAllPlayers();
9798
break;
99+
case "setMixWithOthers":
100+
{
101+
this.mixWithOthers = (boolean) call.arguments;
102+
result.success(null);
103+
break;
104+
}
98105
case "create":
99106
{
100107
TextureRegistry.SurfaceTextureEntry handle =
@@ -104,6 +111,7 @@ public void onMethodCall(MethodCall call, Result result) {
104111
flutterState.binaryMessenger, "flutter.io/videoPlayer/videoEvents" + handle.id());
105112

106113
VideoPlayer player;
114+
VideoPlayerOptions options = new VideoPlayerOptions(mixWithOthers);
107115
if (call.argument("asset") != null) {
108116
String assetLookupKey;
109117
if (call.argument("package") != null) {
@@ -120,7 +128,8 @@ public void onMethodCall(MethodCall call, Result result) {
120128
handle,
121129
"asset:///" + assetLookupKey,
122130
result,
123-
null);
131+
null,
132+
options);
124133
videoPlayers.put(handle.id(), player);
125134
} else {
126135
player =
@@ -130,7 +139,8 @@ public void onMethodCall(MethodCall call, Result result) {
130139
handle,
131140
call.argument("uri"),
132141
result,
133-
call.argument("formatHint"));
142+
call.argument("formatHint"),
143+
options);
134144
videoPlayers.put(handle.id(), player);
135145
}
136146
break;

0 commit comments

Comments
 (0)