[Android] mediaplayer: hide surfaces callbacks

Thomas Guillem git at videolan.org
Fri Jul 3 14:21:47 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Jul  3 14:16:33 2015 +0200| [c3d9f89e54a3cd8ec081f9ed79fbdba88579af01] | committer: Thomas Guillem

mediaplayer: hide surfaces callbacks

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c3d9f89e54a3cd8ec081f9ed79fbdba88579af01
---

 libvlc/src/org/videolan/libvlc/MediaPlayer.java |   48 +++++++++++------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 2c021b6..1aa154d 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -22,10 +22,8 @@
 
 package org.videolan.libvlc;
 
-import java.util.Map;
-
 @SuppressWarnings("unused")
-public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow.SurfaceCallback {
+public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
 
     public static class Event extends VLCEvent {
         //public static final int MediaChanged        = 0x100;
@@ -180,9 +178,30 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow
     private Media mMedia = null;
     private boolean mPlaying = false;
     private boolean mPlayRequested = false;
-    private final AWindow mWindow = new AWindow(this);
     private int mVoutCount = 0;
 
+    private final AWindow mWindow = new AWindow(new AWindow.SurfaceCallback() {
+        @Override
+        public synchronized void onSurfacesCreated(AWindow vout) {
+            if (!mPlaying && mPlayRequested)
+                play();
+        }
+
+        @Override
+        public synchronized void onSurfacesDestroyed(AWindow vout) {
+            if (mVoutCount > 0)
+                setVideoTrack(-1);
+        /* Wait for Vout destruction (mVoutCount = 0) in order to be sure that the surface is not
+         * used after leaving this callback. This shouldn't be needed when using MediaCodec or
+         * AndroidWindow (i.e. after Android 2.3) since the surface is ref-counted */
+            while (mVoutCount > 0) {
+                try {
+                    wait();
+                } catch (InterruptedException ignored) {}
+            }
+        }
+    });
+
     /**
      * Create an empty MediaPlayer
      *
@@ -263,27 +282,6 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow
         nativeStop();
     }
 
-
-    @Override
-    public synchronized void onSurfacesCreated(AWindow vout) {
-        if (!mPlaying && mPlayRequested)
-            play();
-    }
-
-    @Override
-    public synchronized void onSurfacesDestroyed(AWindow vout) {
-        if (mVoutCount > 0)
-            setVideoTrack(-1);
-        /* Wait for Vout destruction (mVoutCount = 0) in order to be sure that the surface is not
-         * used after leaving this callback. This shouldn't be needed when using MediaCodec or
-         * AndroidWindow (i.e. after Android 2.3) since the surface is ref-counted */
-        while (mVoutCount > 0) {
-            try {
-                wait();
-            } catch (InterruptedException ignored) {}
-        }
-    }
-
     /**
      * Set if, and how, the video title will be shown when media is played
      *



More information about the Android mailing list