5252
5353public 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,12 @@ public void onMethodCall(MethodCall call, Result result) {
321335 case "init" :
322336 disposeAllPlayers ();
323337 break ;
338+ case "setMixWithOthers" :
339+ {
340+ this .mixWithOthers = (boolean ) call .arguments ;
341+ result .success (null );
342+ break ;
343+ }
324344 case "create" :
325345 {
326346 TextureRegistry .SurfaceTextureEntry handle = textures .createSurfaceTexture ();
@@ -329,6 +349,7 @@ public void onMethodCall(MethodCall call, Result result) {
329349 registrar .messenger (), "flutter.io/videoPlayer/videoEvents" + handle .id ());
330350
331351 VideoPlayer player ;
352+ VideoPlayerOptions options = new VideoPlayerOptions (mixWithOthers );
332353 if (call .argument ("asset" ) != null ) {
333354 String assetLookupKey ;
334355 if (call .argument ("package" ) != null ) {
@@ -343,12 +364,18 @@ public void onMethodCall(MethodCall call, Result result) {
343364 eventChannel ,
344365 handle ,
345366 "asset:///" + assetLookupKey ,
346- result );
367+ result ,
368+ options );
347369 videoPlayers .put (handle .id (), player );
348370 } else {
349371 player =
350372 new VideoPlayer (
351- registrar .context (), eventChannel , handle , call .argument ("uri" ), result );
373+ registrar .context (),
374+ eventChannel ,
375+ handle ,
376+ call .argument ("uri" ),
377+ result ,
378+ options );
352379 videoPlayers .put (handle .id (), player );
353380 }
354381 break ;
0 commit comments