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

Commit ddd8718

Browse files
committed
WIP: Android Support mixWithOthers configuration
1 parent f00681f commit ddd8718

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252

5353
public class VideoPlayerPlugin implements MethodCallHandler {
5454

55+
private static class VideoPlayerOptions {
56+
public VideoPlayerOptions(boolean mixWithOthers) {
57+
this.mixWithOthers = mixWithOthers;
58+
}
59+
60+
private final boolean mixWithOthers;
61+
}
62+
5563
private static class VideoPlayer {
5664

5765
private SimpleExoPlayer exoPlayer;
@@ -66,14 +74,18 @@ private static class VideoPlayer {
6674

6775
private boolean isInitialized = false;
6876

77+
private final VideoPlayerOptions options;
78+
6979
VideoPlayer(
7080
Context context,
7181
EventChannel eventChannel,
7282
TextureRegistry.SurfaceTextureEntry textureEntry,
7383
String dataSource,
74-
Result result) {
84+
Result result,
85+
VideoPlayerOptions options) {
7586
this.eventChannel = eventChannel;
7687
this.textureEntry = textureEntry;
88+
this.options = options;
7789

7890
TrackSelector trackSelector = new DefaultTrackSelector();
7991
exoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector);
@@ -154,7 +166,7 @@ public void onCancel(Object o) {
154166

155167
surface = new Surface(textureEntry.surfaceTexture());
156168
exoPlayer.setVideoSurface(surface);
157-
setAudioAttributes(exoPlayer);
169+
setAudioAttributes(exoPlayer, options.mixWithOthers);
158170

159171
exoPlayer.addListener(
160172
new EventListener() {
@@ -198,10 +210,10 @@ private void sendBufferingUpdate() {
198210
}
199211

200212
@SuppressWarnings("deprecation")
201-
private static void setAudioAttributes(SimpleExoPlayer exoPlayer) {
213+
private static void setAudioAttributes(SimpleExoPlayer exoPlayer, boolean isMixMode) {
202214
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
203215
exoPlayer.setAudioAttributes(
204-
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), true);
216+
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), !isMixMode);
205217
} else {
206218
exoPlayer.setAudioStreamType(C.STREAM_TYPE_MUSIC);
207219
}
@@ -295,6 +307,8 @@ private VideoPlayerPlugin(Registrar registrar) {
295307

296308
private final Registrar registrar;
297309

310+
private boolean mixWithOthers = false;
311+
298312
private void disposeAllPlayers() {
299313
for (int i = 0; i < videoPlayers.size(); i++) {
300314
videoPlayers.valueAt(i).dispose();
@@ -321,6 +335,9 @@ public void onMethodCall(MethodCall call, Result result) {
321335
case "init":
322336
disposeAllPlayers();
323337
break;
338+
case "setMixWithOthers":
339+
this.mixWithOthers = call.arguments;
340+
break;
324341
case "create":
325342
{
326343
TextureRegistry.SurfaceTextureEntry handle = textures.createSurfaceTexture();
@@ -329,6 +346,7 @@ public void onMethodCall(MethodCall call, Result result) {
329346
registrar.messenger(), "flutter.io/videoPlayer/videoEvents" + handle.id());
330347

331348
VideoPlayer player;
349+
VideoPlayerOptions options = new VideoPlayerOptions(mixWithOthers);
332350
if (call.argument("asset") != null) {
333351
String assetLookupKey;
334352
if (call.argument("package") != null) {
@@ -343,12 +361,13 @@ public void onMethodCall(MethodCall call, Result result) {
343361
eventChannel,
344362
handle,
345363
"asset:///" + assetLookupKey,
346-
result);
364+
result,
365+
options);
347366
videoPlayers.put(handle.id(), player);
348367
} else {
349368
player =
350369
new VideoPlayer(
351-
registrar.context(), eventChannel, handle, call.argument("uri"), result);
370+
registrar.context(), eventChannel, handle, call.argument("uri"), result, options);
352371
videoPlayers.put(handle.id(), player);
353372
}
354373
break;

0 commit comments

Comments
 (0)