[Android] MediaPlayer: reset vout count when player is stopped

Thomas Guillem git at videolan.org
Thu Jul 2 15:49:12 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jul  2 15:49:07 2015 +0200| [7ee4d804e5f763b5c000c4b05af11e1e8c1ec5b6] | committer: Thomas Guillem

MediaPlayer: reset vout count when player is stopped

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

 libvlc/src/org/videolan/libvlc/MediaPlayer.java |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 1921e2d..faeb9ea 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -257,13 +257,15 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow
 
     @Override
     public synchronized void onSurfacesDestroyed(AWindow vout) {
-        if (mPlaying) {
+        if (mVoutCount > 0)
             setVideoTrackEnabled(false);
-            while (mVoutCount > 0) {
-                try {
-                    wait();
-                } catch (InterruptedException ignored) {}
-            }
+        /* 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) {}
         }
     }
 
@@ -434,11 +436,13 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> implements AWindow
     @Override
     protected Event onEventNative(int eventType, long arg1, float arg2) {
         switch (eventType) {
-            case Event.Playing:
-            case Event.Paused:
             case Event.Stopped:
             case Event.EndReached:
             case Event.EncounteredError:
+                mVoutCount = 0;
+                notify();
+            case Event.Playing:
+            case Event.Paused:
                 return new Event(eventType);
             case Event.TimeChanged:
                 return new Event(eventType, arg1);



More information about the Android mailing list