[Android] [PATCH 10/14] MediaWrapper: use Media class
Thomas Guillem
thomas at gllm.fr
Fri Jan 16 17:12:10 CET 2015
---
vlc-android/src/org/videolan/vlc/MediaWrapper.java | 151 ++++++++++-----------
1 file changed, 72 insertions(+), 79 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaWrapper.java b/vlc-android/src/org/videolan/vlc/MediaWrapper.java
index 96ee0d1..a42ec7d 100644
--- a/vlc-android/src/org/videolan/vlc/MediaWrapper.java
+++ b/vlc-android/src/org/videolan/vlc/MediaWrapper.java
@@ -25,7 +25,9 @@ import java.util.Locale;
import org.videolan.libvlc.util.Extensions;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcUtil;
-import org.videolan.libvlc.TrackInfo;
+import org.videolan.libvlc.Media;
+import org.videolan.libvlc.Media.VideoTrack;
+import org.videolan.libvlc.Media.Meta;
import android.graphics.Bitmap;
import android.os.Parcel;
@@ -41,7 +43,6 @@ public class MediaWrapper implements Parcelable {
public final static int TYPE_AUDIO = 1;
public final static int TYPE_GROUP = 2;
- /** Metadata from libvlc_media */
protected String mTitle;
private String mArtist;
private String mGenre;
@@ -59,33 +60,7 @@ public class MediaWrapper implements Parcelable {
private String mTrackID;
private String mArtworkURL;
- public final static int libvlc_meta_Title = 0;
- public final static int libvlc_meta_Artist = 1;
- public final static int libvlc_meta_Genre = 2;
-// public final static int libvlc_meta_Copyright = 3;
- public final static int libvlc_meta_Album = 4;
-// public final static int libvlc_meta_TrackNumber = 5;
-// public final static int libvlc_meta_Description = 6;
-// public final static int libvlc_meta_Rating = 7;
-// public final static int libvlc_meta_Date = 8;
-// public final static int libvlc_meta_Setting = 9;
-// public final static int libvlc_meta_URL = 10;
-// public final static int libvlc_meta_Language = 11;
- public final static int libvlc_meta_NowPlaying = 12;
-// public final static int libvlc_meta_Publisher = 13;
-// public final static int libvlc_meta_EncodedBy = 14;
- public final static int libvlc_meta_ArtworkURL = 15;
-// public final static int libvlc_meta_TrackID = 16;
-// public final static int libvlc_meta_TrackTotal = 17;
-// public final static int libvlc_meta_Director = 18;
-// public final static int libvlc_meta_Season = 19;
-// public final static int libvlc_meta_Episode = 20;
-// public final static int libvlc_meta_ShowName = 21;
-// public final static int libvlc_meta_Actors = 22;
- public final static int libvlc_meta_AlbumArtist = 23;
-// public final static int libvlc_meta_DiscNumber = 24;
-
- private final String mLocation;
+ private String mLocation;
private String mFilename;
private long mTime = 0;
private int mAudioTrack = -1;
@@ -98,63 +73,50 @@ public class MediaWrapper implements Parcelable {
private boolean mIsPictureParsed;
private int mFlags = 0;
+
/**
- * Create a new Media
+ * Create a new MediaWrapper
* @param libVLC A pointer to the libVLC instance. Should not be NULL
* @param URI The URI of the media.
*/
- public MediaWrapper(LibVLC libVLC, String URI) {
+ public MediaWrapper(LibVLC libVLC, String mrl) {
if(libVLC == null)
throw new NullPointerException("libVLC was null");
- mLocation = URI;
-
- mType = TYPE_ALL;
- TrackInfo[] tracks = libVLC.readTracksInfo(mLocation);
+ final Media media = new Media(libVLC, mrl);
+ media.parse();
+ media.release();
+ init(media);
+ }
- extractTrackInfo(tracks);
+ /**
+ * Create a new MediaWrapper
+ * @param media should be parsed
+ */
+ public MediaWrapper(Media media) {
+ init(media);
}
- private void extractTrackInfo(TrackInfo[] tracks) {
- if (tracks == null) {
- mTitle = null;
- mArtist = null;
- mAlbum = null;
- mGenre = null;
- mAlbumArtist = null;
- return;
- }
+ private void init(Media media) {
+
+ mLocation = media.getMrl();
+ mLength = media.getDuration();
+
+ mType = TYPE_ALL;
- for (TrackInfo track : tracks) {
- if (track.Type == TrackInfo.TYPE_VIDEO) {
+ 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 = track.Width;
- mHeight = track.Height;
- } else if (mType == TYPE_ALL && track.Type == TrackInfo.TYPE_AUDIO){
+ mWidth = videoTrack.width;
+ mHeight = videoTrack.height;
+ } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
mType = TYPE_AUDIO;
- } else if (track.Type == TrackInfo.TYPE_META) {
- mLength = track.Length;
- mTitle = track.Title != null ? track.Title.trim() : null;
- mArtist = track.Artist != null ? track.Artist.trim() : null;
- mAlbum = track.Album != null ? track.Album.trim() : null;
- mGenre = track.Genre != null ? track.Genre.trim() : null;
- mAlbumArtist = track.AlbumArtist != null ? track.AlbumArtist.trim() : null;
- mArtworkURL = track.ArtworkURL;
- mNowPlaying = track.NowPlaying;
- if (!TextUtils.isEmpty(track.TrackNumber)) {
- try {
- mTrackNumber = Integer.parseInt(track.TrackNumber);
- } catch (NumberFormatException ignored) {
- }
- }
- 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) {
@@ -166,6 +128,7 @@ public class MediaWrapper implements Parcelable {
}
}
}
+ updateMeta(media);
}
private void init(long time, long length, int type,
@@ -221,14 +184,44 @@ public class MediaWrapper implements Parcelable {
return mLocation;
}
+ private static String getMetaId(Media media, int id, boolean trim) {
+ String meta = media.getMeta(id);
+ return meta != null ? trim ? meta.trim() : meta : null;
+ }
+
+ public void updateMeta(Media media) {
+ mTitle = getMetaId(media, Meta.Title, true);
+ mArtist = getMetaId(media, Meta.Artist, true);
+ mAlbum = getMetaId(media, Meta.Album, true);
+ mGenre = getMetaId(media, Meta.Genre, true);
+ mAlbumArtist = getMetaId(media, Meta.AlbumArtist, true);
+ mArtworkURL = getMetaId(media, Meta.ArtworkURL, false);
+ mNowPlaying = getMetaId(media, Meta.NowPlaying, false);
+ final String trackNumber = getMetaId(media, Meta.TrackNumber, false);
+ if (!TextUtils.isEmpty(trackNumber)) {
+ try {
+ mTrackNumber = Integer.parseInt(trackNumber);
+ } catch (NumberFormatException ignored) {
+ }
+ }
+ Log.d(TAG, "Title " + mTitle);
+ Log.d(TAG, "Artist " + mArtist);
+ Log.d(TAG, "Genre " + mGenre);
+ Log.d(TAG, "Album " + mAlbum);
+ }
+
+ /*
+ * XXX to remove
+ */
public void updateMeta(LibVLC libVLC) {
- mTitle = libVLC.getMeta(libvlc_meta_Title);
- mArtist = libVLC.getMeta(libvlc_meta_Artist);
- mGenre = libVLC.getMeta(libvlc_meta_Genre);
- mAlbum = libVLC.getMeta(libvlc_meta_Album);
- mAlbumArtist = libVLC.getMeta(libvlc_meta_AlbumArtist);
- mNowPlaying = libVLC.getMeta(libvlc_meta_NowPlaying);
- mArtworkURL = libVLC.getMeta(libvlc_meta_ArtworkURL);
+ mTitle = libVLC.getMeta(Meta.Title);
+ mArtist = libVLC.getMeta(Meta.Artist);
+ mGenre = libVLC.getMeta(Meta.Genre);
+ mAlbum = libVLC.getMeta(Meta.Album);
+ mAlbumArtist = libVLC.getMeta(Meta.AlbumArtist);
+ mNowPlaying = libVLC.getMeta(Meta.NowPlaying);
+ mArtworkURL = libVLC.getMeta(Meta.ArtworkURL);
+
}
public String getFileName() {
@@ -443,4 +436,4 @@ public class MediaWrapper implements Parcelable {
return new MediaWrapper[size];
}
};
-}
+}
\ No newline at end of file
--
2.1.3
More information about the Android
mailing list