[Android] [PATCH 2/3] MediaWrapper: init: media can be null

Thomas Guillem thomas at gllm.fr
Fri Jan 23 10:41:04 CET 2015


---
 vlc-android/src/org/videolan/vlc/MediaWrapper.java | 34 ++++++++++++----------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaWrapper.java b/vlc-android/src/org/videolan/vlc/MediaWrapper.java
index d8f8f90..a391632 100644
--- a/vlc-android/src/org/videolan/vlc/MediaWrapper.java
+++ b/vlc-android/src/org/videolan/vlc/MediaWrapper.java
@@ -104,26 +104,29 @@ public class MediaWrapper implements Parcelable {
     }
 
     private void init(Media media) {
-
-        mLength = media.getDuration();
-
         mType = TYPE_ALL;
 
-        if (media.isParsed()) {
-            for (int i = 0; i < media.getTrackCount(); ++i) {
-                final Media.Track track = media.getTrack(i);
-                if (track == null)
-                    continue;
-                if (track.type == Media.Track.Type.Video) {
-                    final Media.VideoTrack videoTrack = (VideoTrack) track;
-                    mType = TYPE_VIDEO;
-                    mWidth = videoTrack.width;
-                    mHeight = videoTrack.height;
-                } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
-                    mType = TYPE_AUDIO;
+        if (media != null) {
+            if (media.isParsed()) {
+                mLength = media.getDuration();
+
+                for (int i = 0; i < media.getTrackCount(); ++i) {
+                    final Media.Track track = media.getTrack(i);
+                    if (track == null)
+                        continue;
+                    if (track.type == Media.Track.Type.Video) {
+                        final Media.VideoTrack videoTrack = (VideoTrack) track;
+                        mType = TYPE_VIDEO;
+                        mWidth = videoTrack.width;
+                        mHeight = videoTrack.height;
+                    } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
+                        mType = TYPE_AUDIO;
+                    }
                 }
             }
+            updateMeta(media);
         }
+
         if (mType == TYPE_ALL) {
             int dotIndex = mLocation.lastIndexOf(".");
             if (dotIndex != -1) {
@@ -142,7 +145,6 @@ public class MediaWrapper implements Parcelable {
                 mType = TYPE_DIR;
             }
         }
-        updateMeta(media);
     }
 
     private void init(long time, long length, int type,
-- 
2.1.3



More information about the Android mailing list