[Android] Util: add getOrCreateMedia

Edward Wang git at videolan.org
Tue Sep 2 10:12:25 CEST 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Tue Sep  2 00:33:22 2014 -0700| [8100f16213c5ab5b3616d422a35ec94f25206c1d] | committer: Edward Wang

Util: add getOrCreateMedia

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

 vlc-android/src/org/videolan/vlc/util/Util.java |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index a172ec3..6276d8b 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -25,6 +25,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 
+import org.videolan.libvlc.LibVLC;
+import org.videolan.libvlc.Media;
+import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.VLCApplication;
 
 import android.content.Context;
@@ -77,6 +80,21 @@ public class Util {
     }
 
     /**
+     * Retrieve the existing media object from the media library or create a
+     * new one from the given MRL.
+     *
+     * @param libVLC LibVLC instance
+     * @param mrl MRL of the media
+     * @return A media object from the media library or newly created
+     */
+    public static Media getOrCreateMedia(LibVLC libVLC, String mrl) {
+        Media mlItem = MediaLibrary.getInstance().getMediaItem(mrl);
+        if(mlItem == null)
+            mlItem = new Media(libVLC, mrl);
+        return mlItem;
+    }
+
+    /**
      * Get a resource id from an attribute id.
      * @param context
      * @param attrId



More information about the Android mailing list