52
52
53
53
public class VideoPlayerPlugin implements MethodCallHandler {
54
54
55
+ private static class VideoPlayerOptions {
56
+ public VideoPlayerOptions (boolean mixWithOthers ) {
57
+ this .mixWithOthers = mixWithOthers ;
58
+ }
59
+
60
+ private final boolean mixWithOthers ;
61
+ }
62
+
55
63
private static class VideoPlayer {
56
64
57
65
private SimpleExoPlayer exoPlayer ;
@@ -66,14 +74,18 @@ private static class VideoPlayer {
66
74
67
75
private boolean isInitialized = false ;
68
76
77
+ private final VideoPlayerOptions options ;
78
+
69
79
VideoPlayer (
70
80
Context context ,
71
81
EventChannel eventChannel ,
72
82
TextureRegistry .SurfaceTextureEntry textureEntry ,
73
83
String dataSource ,
74
- Result result ) {
84
+ Result result ,
85
+ VideoPlayerOptions options ) {
75
86
this .eventChannel = eventChannel ;
76
87
this .textureEntry = textureEntry ;
88
+ this .options = options ;
77
89
78
90
TrackSelector trackSelector = new DefaultTrackSelector ();
79
91
exoPlayer = ExoPlayerFactory .newSimpleInstance (context , trackSelector );
@@ -154,7 +166,7 @@ public void onCancel(Object o) {
154
166
155
167
surface = new Surface (textureEntry .surfaceTexture ());
156
168
exoPlayer .setVideoSurface (surface );
157
- setAudioAttributes (exoPlayer );
169
+ setAudioAttributes (exoPlayer , options . mixWithOthers );
158
170
159
171
exoPlayer .addListener (
160
172
new EventListener () {
@@ -198,10 +210,10 @@ private void sendBufferingUpdate() {
198
210
}
199
211
200
212
@ SuppressWarnings ("deprecation" )
201
- private static void setAudioAttributes (SimpleExoPlayer exoPlayer ) {
213
+ private static void setAudioAttributes (SimpleExoPlayer exoPlayer , boolean isMixMode ) {
202
214
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
203
215
exoPlayer .setAudioAttributes (
204
- new AudioAttributes .Builder ().setContentType (C .CONTENT_TYPE_MOVIE ).build (), true );
216
+ new AudioAttributes .Builder ().setContentType (C .CONTENT_TYPE_MOVIE ).build (), ! isMixMode );
205
217
} else {
206
218
exoPlayer .setAudioStreamType (C .STREAM_TYPE_MUSIC );
207
219
}
@@ -295,6 +307,8 @@ private VideoPlayerPlugin(Registrar registrar) {
295
307
296
308
private final Registrar registrar ;
297
309
310
+ private boolean mixWithOthers = false ;
311
+
298
312
private void disposeAllPlayers () {
299
313
for (int i = 0 ; i < videoPlayers .size (); i ++) {
300
314
videoPlayers .valueAt (i ).dispose ();
@@ -321,6 +335,9 @@ public void onMethodCall(MethodCall call, Result result) {
321
335
case "init" :
322
336
disposeAllPlayers ();
323
337
break ;
338
+ case "setMixWithOthers" :
339
+ this .mixWithOthers = call .arguments ;
340
+ break ;
324
341
case "create" :
325
342
{
326
343
TextureRegistry .SurfaceTextureEntry handle = textures .createSurfaceTexture ();
@@ -329,6 +346,7 @@ public void onMethodCall(MethodCall call, Result result) {
329
346
registrar .messenger (), "flutter.io/videoPlayer/videoEvents" + handle .id ());
330
347
331
348
VideoPlayer player ;
349
+ VideoPlayerOptions options = new VideoPlayerOptions (mixWithOthers );
332
350
if (call .argument ("asset" ) != null ) {
333
351
String assetLookupKey ;
334
352
if (call .argument ("package" ) != null ) {
@@ -343,12 +361,13 @@ public void onMethodCall(MethodCall call, Result result) {
343
361
eventChannel ,
344
362
handle ,
345
363
"asset:///" + assetLookupKey ,
346
- result );
364
+ result ,
365
+ options );
347
366
videoPlayers .put (handle .id (), player );
348
367
} else {
349
368
player =
350
369
new VideoPlayer (
351
- registrar .context (), eventChannel , handle , call .argument ("uri" ), result );
370
+ registrar .context (), eventChannel , handle , call .argument ("uri" ), result , options );
352
371
videoPlayers .put (handle .id (), player );
353
372
}
354
373
break ;
0 commit comments