[Android] MediaPlayer: Prevent IllegalStateException

Geoffrey Métais git at videolan.org
Mon Jun 3 10:29:48 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jun  3 10:15:37 2019 +0200| [edabe272c66a5b10be274f848d50071fbb78d1b8] | committer: Geoffrey Métais

MediaPlayer: Prevent IllegalStateException

> https://code.videolan.org/videolan/vlc-android/commit/edabe272c66a5b10be274f848d50071fbb78d1b8
---

 libvlc/src/org/videolan/libvlc/MediaPlayer.java | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index c7db77a8f..31df150a2 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -36,6 +36,10 @@ import android.net.Uri;
 import android.os.Build;
 import android.util.SparseArray;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.RequiresApi;
+
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.libvlc.util.DisplayManager;
 import org.videolan.libvlc.util.VLCUtil;
@@ -44,10 +48,6 @@ import org.videolan.libvlc.util.VLCVideoLayout;
 import java.io.File;
 import java.io.IOException;
 
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
 @SuppressWarnings("unused, JniMissingFunction")
 public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
 
@@ -1031,9 +1031,8 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
     public void setVideoTrackEnabled(boolean enabled) {
         if (!enabled) {
             setVideoTrack(-1);
-        } else if (getVideoTrack() == -1) {
+        } else if (!isReleased() && hasMedia() && getVideoTrack() == -1) {
             final MediaPlayer.TrackDescription tracks[] = getVideoTracks();
-
             if (tracks != null) {
                 for (MediaPlayer.TrackDescription track : tracks) {
                     if (track.id != -1) {



More information about the Android mailing list