[Android] MediaWrapper: init: media can be null

Thomas Guillem git at videolan.org
Fri Jan 23 13:01:18 CET 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Jan 23 10:23:56 2015 +0100| [ae6d219163916c9fa111c4a13d29dc55ba14b171] | committer: Thomas Guillem

MediaWrapper: init: media can be null

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

 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,



More information about the Android mailing list