[Android] Media: Factor the Java track-reading code

Edward Wang git at videolan.org
Tue Aug 28 17:12:43 CEST 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Wed Aug 22 17:15:12 2012 -0400| [f3ae5e9ec2a45de1e4fc9bd6cf0715777f059143] | committer: Jean-Baptiste Kempf

Media: Factor the Java track-reading code

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 vlc-android/src/org/videolan/vlc/Media.java |   86 +++++++++++++++++----------
 1 file changed, 53 insertions(+), 33 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index 6dd5213..509fb39 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -133,39 +133,7 @@ public class Media implements Comparable<Media> {
 
             TrackInfo[] tracks = mLibVlc.readTracksInfo(mLocation);
 
-            for (TrackInfo track : tracks) {
-                if (track.Type == TrackInfo.TYPE_VIDEO) {
-                    mType = TYPE_VIDEO;
-                    mWidth = track.Width;
-                    mHeight = track.Height;
-                } else if (mType == TYPE_ALL && track.Type == TrackInfo.TYPE_AUDIO){
-                    mType = TYPE_AUDIO;
-                } else if (track.Type == TrackInfo.TYPE_META) {
-                    mLength = track.Length;
-                    mTitle = track.Title;
-                    mArtist = Util.getValue(track.Artist, R.string.unknown_artist);
-                    mAlbum = Util.getValue(track.Album, R.string.unknown_album);
-                    mGenre = Util.getValue(track.Genre, R.string.unknown_genre);
-                    mArtworkURL = track.ArtworkURL;
-                    Log.d(TAG, "Title " + mTitle);
-                    Log.d(TAG, "Artist " + mArtist);
-                    Log.d(TAG, "Genre " + mGenre);
-                    Log.d(TAG, "Album " + mAlbum);
-                }
-            }
-
-            /* No useful ES found */
-            if (mType == TYPE_ALL) {
-                int dotIndex = mLocation.lastIndexOf(".");
-                if (dotIndex != -1) {
-                    String fileExt = mLocation.substring(dotIndex);
-                    if( Media.VIDEO_EXTENSIONS.contains(fileExt) ) {
-                        mType = TYPE_VIDEO;
-                    } else if (Media.AUDIO_EXTENSIONS.contains(fileExt)) {
-                        mType = TYPE_AUDIO;
-                    }
-                }
-            }
+            extractTrackInfo(tracks);
         } catch (LibVlcException e) {
             e.printStackTrace();
         }
@@ -177,6 +145,58 @@ public class Media implements Comparable<Media> {
         }
     }
 
+    public Media(String URI, int position) {
+        mLocation = URI;
+
+        LibVLC mLibVlc = null;
+        try {
+            mLibVlc = LibVLC.getInstance();
+            mType = TYPE_ALL;
+
+            TrackInfo[] tracks = mLibVlc.readTracksInfoPosition(position);
+
+            extractTrackInfo(tracks);
+        } catch (LibVlcException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void extractTrackInfo(TrackInfo[] tracks) {
+        for (TrackInfo track : tracks) {
+            if (track.Type == TrackInfo.TYPE_VIDEO) {
+                mType = TYPE_VIDEO;
+                mWidth = track.Width;
+                mHeight = track.Height;
+            } else if (mType == TYPE_ALL && track.Type == TrackInfo.TYPE_AUDIO){
+                mType = TYPE_AUDIO;
+            } else if (track.Type == TrackInfo.TYPE_META) {
+                mLength = track.Length;
+                mTitle = track.Title;
+                mArtist = Util.getValue(track.Artist, R.string.unknown_artist);
+                mAlbum = Util.getValue(track.Album, R.string.unknown_album);
+                mGenre = Util.getValue(track.Genre, R.string.unknown_genre);
+                mArtworkURL = track.ArtworkURL;
+                Log.d(TAG, "Title " + mTitle);
+                Log.d(TAG, "Artist " + mArtist);
+                Log.d(TAG, "Genre " + mGenre);
+                Log.d(TAG, "Album " + mAlbum);
+            }
+        }
+
+        /* No useful ES found */
+        if (mType == TYPE_ALL) {
+            int dotIndex = mLocation.lastIndexOf(".");
+            if (dotIndex != -1) {
+                String fileExt = mLocation.substring(dotIndex);
+                if( Media.VIDEO_EXTENSIONS.contains(fileExt) ) {
+                    mType = TYPE_VIDEO;
+                } else if (Media.AUDIO_EXTENSIONS.contains(fileExt)) {
+                    mType = TYPE_AUDIO;
+                }
+            }
+        }
+    }
+
     public Media(Context context, String location, long time, long length, int type,
             Bitmap picture, String title, String artist, String genre, String album,
             int width, int height, String artworkURL) {



More information about the Android mailing list