[Android] [PATCH] Use MRLs and libvlc_media_new_location everywhere

Edward Wang edward.c.wang at compdigitec.com
Sat Mar 31 18:18:18 CEST 2012


---
 Fix a small double-encoding bug in the patch. Version as of 31 March 2012

 vlc-android/jni/Android.mk                         |    1 +
 vlc-android/jni/libvlcjni.c                        |   34 +++++++---
 vlc-android/src/org/videolan/vlc/AudioService.java |   16 ++--
 .../src/org/videolan/vlc/DatabaseManager.java      |   40 ++++++-----
 vlc-android/src/org/videolan/vlc/LibVLC.java       |   20 +++---
 vlc-android/src/org/videolan/vlc/Media.java        |   74 +++++++++++++------
 vlc-android/src/org/videolan/vlc/MediaLibrary.java |   27 ++++----
 .../src/org/videolan/vlc/ThumbnailerManager.java   |    2 +-
 vlc-android/src/org/videolan/vlc/Util.java         |   15 ++++
 .../src/org/videolan/vlc/gui/SearchActivity.java   |   10 ++--
 .../vlc/gui/audio/AudioBrowserActivity.java        |   14 ++--
 .../videolan/vlc/gui/audio/AudioListActivity.java  |   14 ++--
 .../vlc/gui/audio/AudioPlaylistAdapter.java        |    2 +-
 .../vlc/gui/audio/AudioSongsListAdapter.java       |   16 ++--
 .../videolan/vlc/gui/video/MediaInfoActivity.java  |   10 ++--
 .../videolan/vlc/gui/video/VideoListActivity.java  |    2 +-
 .../videolan/vlc/gui/video/VideoListAdapter.java   |   10 ++--
 .../vlc/gui/video/VideoPlayerActivity.java         |   20 +++---
 .../org/videolan/vlc/interfaces/IAudioService.aidl |    2 +-
 19 files changed, 195 insertions(+), 134 deletions(-)

diff --git a/vlc-android/jni/Android.mk b/vlc-android/jni/Android.mk
index 95aafcb..dbf53b8 100644
--- a/vlc-android/jni/Android.mk
+++ b/vlc-android/jni/Android.mk
@@ -19,6 +19,7 @@ else
 CPP_STATIC=$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/libs/$(ARCH)/libgnustl_static.a
 endif

+LOCAL_CFLAGS := -std=gnu99
 LOCAL_LDLIBS := -L$(VLC_CONTRIB)/lib \
 	$(VLC_MODULES) \
 	$(VLC_BUILD_DIR)/lib/.libs/libvlc.a \
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index ee8bf31..388fa9d 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -22,6 +22,8 @@
 #include <pthread.h>

 #include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_url.h>

 #include <jni.h>

@@ -34,13 +36,13 @@
 #define LOG_TAG "VLC/JNI/main"
 #include "log.h"

-libvlc_media_t *new_media(jint instance, JNIEnv *env, jobject thiz, jstring filePath)
+libvlc_media_t *new_media(jint instance, JNIEnv *env, jobject thiz, jstring fileLocation)
 {
     libvlc_instance_t *libvlc = (libvlc_instance_t*)instance;
     jboolean isCopy;
-    const char *psz_path = (*env)->GetStringUTFChars(env, filePath, &isCopy);
-    libvlc_media_t *p_md = libvlc_media_new_path(libvlc, psz_path);
-    (*env)->ReleaseStringUTFChars(env, filePath, psz_path);
+    const char *psz_location = (*env)->GetStringUTFChars(env, fileLocation, &isCopy);
+    libvlc_media_t *p_md = libvlc_media_new_location(libvlc, psz_location);
+    (*env)->ReleaseStringUTFChars(env, fileLocation, psz_location);
     if (!p_md)
         return NULL;

@@ -245,6 +247,20 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
     LOGI("LibVLC initialized: %p", instance);
 }

+jstring Java_org_videolan_vlc_LibVLC_nativeToURI(JNIEnv *env, jobject thiz, jstring path)
+{
+    jboolean isCopy;
+    /* Get C string */
+    const char* psz_path = (*env)->GetStringUTFChars(env, path, &isCopy);
+    /* Convert the path to URI */
+    char* psz_location = make_URI(psz_path, "file");
+    /* Box into jstring */
+    jstring t = (*env)->NewStringUTF(env, psz_location);
+    /* Clean up */
+    (*env)->ReleaseStringUTFChars(env, path, psz_path);
+    free(psz_location);
+    return t;
+}

 void Java_org_videolan_vlc_LibVLC_nativeDestroy(JNIEnv *env, jobject thiz)
 {
@@ -444,10 +460,10 @@ void Java_org_videolan_vlc_LibVLC_readMedia(JNIEnv *env, jobject thiz,
 }

 jboolean Java_org_videolan_vlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz,
-                                                    jint i_instance, jstring filePath)
+                                                    jint i_instance, jstring fileLocation)
 {
     /* Create a new item and assign it to the media player. */
-    libvlc_media_t *p_m = new_media(i_instance, env, thiz, filePath);
+    libvlc_media_t *p_m = new_media(i_instance, env, thiz, fileLocation);
     if (p_m == NULL)
     {
         LOGE("Couldn't create the media!");
@@ -558,8 +574,8 @@ static void length_changed_callback(const libvlc_event_t *ev, void *data)
     pthread_mutex_unlock(&monitor->doneMutex);
 }

-jlong Java_org_videolan_vlc_LibVLC_getLengthFromFile(JNIEnv *env, jobject thiz,
-                                                     jint i_instance, jstring filePath)
+jlong Java_org_videolan_vlc_LibVLC_getLengthFromLocation(JNIEnv *env, jobject thiz,
+                                                     jint i_instance, jstring fileLocation)
 {
     jlong length = 0;
     struct length_change_monitor *monitor;
@@ -573,7 +589,7 @@ jlong Java_org_videolan_vlc_LibVLC_getLengthFromFile(JNIEnv *env, jobject thiz,
     monitor->length_changed = false;

     /* Create a new item and assign it to the media player. */
-    libvlc_media_t *m = new_media(i_instance, env, thiz, filePath);
+    libvlc_media_t *m = new_media(i_instance, env, thiz, fileLocation);
     if (m == NULL)
     {
         LOGE("Couldn't create the media to play!");
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 233c276..81bbcf9 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -292,7 +292,7 @@ public class AudioService extends Service {
                 return;
             }
         }
-        mLibVLC.readMedia(mCurrentMedia.getPath());
+        mLibVLC.readMedia(mCurrentMedia.getLocation());
         mHandler.sendEmptyMessage(SHOW_PROGRESS);
         showNotification();
         updateWidget(this);
@@ -306,7 +306,7 @@ public class AudioService extends Service {
             mCurrentMedia = mMediaList.get(index - 1);
         else
             return;
-        mLibVLC.readMedia(mCurrentMedia.getPath());
+        mLibVLC.readMedia(mCurrentMedia.getLocation());
         mHandler.sendEmptyMessage(SHOW_PROGRESS);
         showNotification();
         updateWidget(this);
@@ -344,7 +344,7 @@ public class AudioService extends Service {
                 if (b != null)
                     return b;
             }
-            File f = new File(mCurrentMedia.getPath());
+            File f = new File(mCurrentMedia.getLocation());
             for (File s : f.getParentFile().listFiles()) {
                 if (s.getAbsolutePath().endsWith("png") ||
                         s.getAbsolutePath().endsWith("jpg"))
@@ -358,8 +358,8 @@ public class AudioService extends Service {
     private IAudioService.Stub mInterface = new IAudioService.Stub() {

         @Override
-        public String getCurrentMediaPath() throws RemoteException {
-            return mCurrentMedia.getPath();
+        public String getCurrentMediaLocation() throws RemoteException {
+            return mCurrentMedia.getLocation();
         }

         @Override
@@ -478,7 +478,7 @@ public class AudioService extends Service {
             }

             if (mCurrentMedia != null)
-                mLibVLC.readMedia(mCurrentMedia.getPath());
+                mLibVLC.readMedia(mCurrentMedia.getLocation());
             showNotification();
         }

@@ -501,14 +501,14 @@ public class AudioService extends Service {
             ArrayList<String> medias = new ArrayList<String>();
             for (int i = 0; i < mMediaList.size(); i++) {
                 Media item = mMediaList.get(i);
-                medias.add(item.getPath());
+                medias.add(item.getLocation());
             }
             return medias;
         }

         public String getItem() {
             return mCurrentMedia != null
-                    ? mCurrentMedia.getPath()
+                    ? mCurrentMedia.getLocation()
                     : null;
         }

diff --git a/vlc-android/src/org/videolan/vlc/DatabaseManager.java b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
index bfc4358..162445d 100644
--- a/vlc-android/src/org/videolan/vlc/DatabaseManager.java
+++ b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
@@ -51,7 +51,7 @@ public class DatabaseManager {
     private final String DIR_ROW_PATH = "path";

     private final String MEDIA_TABLE_NAME = "media_table";
-    private final String MEDIA_PATH = "path";
+    private final String MEDIA_LOCATION = "location";
     private final String MEDIA_TIME = "time";
     private final String MEDIA_LENGTH = "length";
     private final String MEDIA_TYPE = "type";
@@ -115,7 +115,7 @@ public class DatabaseManager {

             String createMediaTabelQuery = "CREATE TABLE IF NOT EXISTS "
                     + MEDIA_TABLE_NAME + " ("
-                    + MEDIA_PATH + " TEXT PRIMARY KEY NOT NULL, "
+                    + MEDIA_LOCATION + " TEXT PRIMARY KEY NOT NULL, "
                     + MEDIA_TIME + " INTEGER, "
                     + MEDIA_LENGTH + " INTEGER, "
                     + MEDIA_TYPE + " INTEGER, "
@@ -219,7 +219,7 @@ public class DatabaseManager {

         ContentValues values = new ContentValues();

-        values.put(MEDIA_PATH, media.getPath());
+        values.put(MEDIA_LOCATION, media.getLocation());
         values.put(MEDIA_TIME, media.getTime());
         values.put(MEDIA_LENGTH, media.getLength());
         values.put(MEDIA_TYPE, media.getType());
@@ -259,7 +259,7 @@ public class DatabaseManager {

         cursor = mDb.query(
                 MEDIA_TABLE_NAME,
-                new String[] { MEDIA_PATH },
+                new String[] { MEDIA_LOCATION },
                 null, null, null, null, null);
         cursor.moveToFirst();
         if (!cursor.isAfterLast()) {
@@ -293,7 +293,7 @@ public class DatabaseManager {
                     MEDIA_ARTIST, //5 string
                     MEDIA_GENRE, //6 string
                     MEDIA_ALBUM, //7 string
-                    MEDIA_PATH, //8 string
+                    MEDIA_LOCATION, //8 string
                     MEDIA_TABLE_NAME,
                     CHUNK_SIZE,
                     chunk_count * CHUNK_SIZE), null);
@@ -304,13 +304,15 @@ public class DatabaseManager {
                     if (blob != null) {
                         picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
                     }
-
-                    Media media = new Media(context, new File(cursor.getString(8)), cursor.getLong(0),
-                            cursor.getLong(1), cursor.getInt(2),
+                    String location = cursor.getString(8);
+                    File file = Util.URItoFile(location);
+                    Media media = new Media(context, location, file.getName().substring(0, file.getName().lastIndexOf('.')),
+                            cursor.getLong(0), cursor.getLong(1), cursor.getInt(2),
                             picture, cursor.getString(4),
                             cursor.getString(5), cursor.getString(6),
                             cursor.getString(7));
-                    medias.put(media.getPath(), media);
+                    medias.put(media.getLocation(), media);
+
                     picture = null;
                     count++;
                 } while (cursor.moveToNext());
@@ -323,7 +325,7 @@ public class DatabaseManager {
         return medias;
     }

-    public synchronized Media getMedia(Context context, String path) {
+    public synchronized Media getMedia(Context context, String location) {

         Cursor cursor;
         Media media = null;
@@ -342,8 +344,8 @@ public class DatabaseManager {
                         MEDIA_GENRE, //6 string
                         MEDIA_ALBUM //7 string
                 },
-                MEDIA_PATH + "=?",
-                new String[] { path },
+                MEDIA_LOCATION + "=?",
+                new String[] { location },
                 null, null, null);
         if (cursor.moveToFirst()) {

@@ -351,9 +353,9 @@ public class DatabaseManager {
             if (blob != null) {
                 picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
             }
-
-            media = new Media(context, new File(path), cursor.getLong(0),
-                    cursor.getLong(1), cursor.getInt(2),
+            File file = Util.URItoFile(location);
+            media = new Media(context, location, file.getName().substring(0, file.getName().lastIndexOf('.')),
+                    cursor.getLong(0), cursor.getLong(1), cursor.getInt(2),
                     picture, cursor.getString(4),
                     cursor.getString(5), cursor.getString(6),
                     cursor.getString(7));
@@ -362,11 +364,11 @@ public class DatabaseManager {
         return media;
     }

-    public synchronized void removeMedia(String path) {
-        mDb.delete(MEDIA_TABLE_NAME, MEDIA_PATH + "=?", new String[] { path });
+    public synchronized void removeMedia(String location) {
+        mDb.delete(MEDIA_TABLE_NAME, MEDIA_LOCATION + "=?", new String[] { location });
     }

-    public synchronized void updateMedia(String path, mediaColumn col,
+    public synchronized void updateMedia(String location, mediaColumn col,
             Object object) {
         ContentValues values = new ContentValues();
         switch (col) {
@@ -379,7 +381,7 @@ public class DatabaseManager {
             default:
                 return;
         }
-        mDb.update(MEDIA_TABLE_NAME, values, MEDIA_PATH + "=?", new String[] { path });
+        mDb.update(MEDIA_TABLE_NAME, values, MEDIA_LOCATION + "=?", new String[] { location });
     }

     /**
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 01d59a5..6eaf8ba 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -204,22 +204,22 @@ public class LibVLC {
     /**
      * Get a media thumbnail.
      */
-    public byte[] getThumbnail(String filePath, int i_width, int i_height) {
-        return getThumbnail(mLibVlcInstance, filePath, i_width, i_height);
+    public byte[] getThumbnail(String mrl, int i_width, int i_height) {
+        return getThumbnail(mLibVlcInstance, mrl, i_width, i_height);
     }

     /**
      * Return true if there is a video track in the file
      */
-    public boolean hasVideoTrack(String filePath) {
-        return hasVideoTrack(mLibVlcInstance, filePath);
+    public boolean hasVideoTrack(String mrl) {
+        return hasVideoTrack(mLibVlcInstance, mrl);
     }

     /**
      * Return the length of the stream, in milliseconds
      */
-    public long getLengthFromFile(String filePath) {
-        return getLengthFromFile(mLibVlcInstance, filePath);
+    public long getLengthFromLocation(String mrl) {
+        return getLengthFromLocation(mLibVlcInstance, mrl);
     }

     /**
@@ -335,12 +335,12 @@ public class LibVLC {
      * Get a media thumbnail.
      * @return a bytearray with the RGBA thumbnail data inside.
      */
-    private native byte[] getThumbnail(int instance, String filePath, int i_width, int i_height);
+    private native byte[] getThumbnail(int instance, String mrl, int i_width, int i_height);

     /**
      * Return true if there is a video track in the file
      */
-    private native boolean hasVideoTrack(int instance, String filePath);
+    private native boolean hasVideoTrack(int instance, String mrl);

     private native String[] readMediaMeta(int instance, String mrl);

@@ -358,10 +358,12 @@ public class LibVLC {

     public native int getSpuTracksCount();

+    public native String nativeToURI(String path);
+
     /**
      * Return the length of the stream, in milliseconds
      */
-    private native long getLengthFromFile(int instance, String filePath);
+    private native long getLengthFromLocation(int instance, String mrl);

     private native void setEventManager(EventManager eventManager);

diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index 9f1662c..659a8f7 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -21,6 +21,8 @@
 package org.videolan.vlc;

 import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;

 import android.content.Context;
 import android.graphics.Bitmap;
@@ -62,7 +64,8 @@ public class Media implements Comparable<Media> {
     private String mEncodedBy;
     private String mTrackID;

-    private File mFile;
+    private String mLocation;
+    private String mFilename;
     private long mTime = 0;
     private long mLength = 0;
     private int mType;
@@ -71,19 +74,32 @@ public class Media implements Comparable<Media> {
     private Bitmap mPicture;

     /**
-     * Create an new Media
-     * @param file: path on the local storage
+     * Create a new Media
+     * @param context Application context of the caller
+     * @param MRL the file's MRL (media resource locator)
+     * @param addToDb Should it be added to the file database?
      */
-    public Media(Context context, File file) {
-        this.mFile = file;
+    public Media(Context context, String MRL, Boolean addToDb) {
+        mLocation = MRL;
+        try {
+            URL urlobj = new URL(MRL);
+            mFilename = urlobj.getFile().substring(urlobj.getFile().lastIndexOf('/') + 1);
+            /* empty filenames are awkward */
+            if(mFilename.equals("")) {
+                mFilename = urlobj.getHost();
+            }
+        } catch (MalformedURLException e1) {
+            mFilename = "";
+        }
+

         LibVLC mLibVlc = null;
         try {
             mLibVlc = LibVLC.getInstance();
-            mType = (mLibVlc.hasVideoTrack(file.getPath())) ? TYPE_VIDEO : TYPE_AUDIO;
-            mLength = mLibVlc.getLengthFromFile(file.getPath());
+            mType = (mLibVlc.hasVideoTrack(mLocation)) ? TYPE_VIDEO : TYPE_AUDIO;
+            mLength = mLibVlc.getLengthFromLocation(mLocation);

-            String[] array = mLibVlc.readMediaMeta(file.getPath());
+            String[] array = mLibVlc.readMediaMeta(mLocation);

             int i;
             for (i = 0; i < array.length; i++) {
@@ -108,14 +124,28 @@ public class Media implements Comparable<Media> {
             e.printStackTrace();
         }

-        // Add this item to database
-        DatabaseManager db = DatabaseManager.getInstance(context);
-        db.addMedia(this);
+        if(addToDb) {
+            // Add this item to database
+            DatabaseManager db = DatabaseManager.getInstance(context);
+            db.addMedia(this);
+        }
     }

-    public Media(Context context, File file, long time, long length, int type,
+    /**
+     * Create from file
+     *
+     * @param context Context of the caller
+     * @param file File object of the file to be added
+     */
+    public Media(Context context, File file) {
+        this(context, Util.PathToURI(file.getPath()), true);
+        mFilename = file.getName().substring(0, file.getName().lastIndexOf('.'));
+    }
+
+    public Media(Context context, String location, String filename, long time, long length, int type,
             Bitmap picture, String title, String artist, String genre, String album) {
-        mFile = file;
+        mLocation = location;
+        mFilename = filename;
         mTime = time;
         mLength = length;
         mType = type;
@@ -135,12 +165,8 @@ public class Media implements Comparable<Media> {
                 another.getTitle().toUpperCase());
     }

-    public File getFile() {
-        return mFile;
-    }
-
-    public String getPath() {
-        return mFile.getPath();
+    public String getLocation() {
+        return mLocation;
     }

     public void updateMeta() {
@@ -148,7 +174,7 @@ public class Media implements Comparable<Media> {
     }

     public String getFileName() {
-        return mFile.getName().substring(0, mFile.getName().lastIndexOf('.'));
+        return mFilename;
     }

     public long getTime() {
@@ -182,17 +208,17 @@ public class Media implements Comparable<Media> {
     public void setPicture(Context context, Bitmap p) {
         Log.d(TAG, "Set new picture for " + getTitle());
         DatabaseManager.getInstance(context).updateMedia(
-                mFile.getPath(),
+                mLocation,
                 DatabaseManager.mediaColumn.MEDIA_PICTURE,
                 p);
         mPicture = p;
     }

     public String getTitle() {
-        if (mTitle == null)
-            return mFile.getName().substring(0, mFile.getName().lastIndexOf('.'));
-        else
+        if(mTitle != null)
             return mTitle;
+        else
+            return mFilename;
     }

     public String getArtist() {
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 3a78992..10f8972 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -132,10 +132,10 @@ public class MediaLibrary {
         return mItemList;
     }

-    public Media getMediaItem(String path) {
+    public Media getMediaItem(String location) {
         for (int i = 0; i < mItemList.size(); i++) {
             Media item = mItemList.get(i);
-            if (item.getPath().equals(path)) {
+            if (item.getLocation().equals(location)) {
                 return item;
             }
         }
@@ -183,9 +183,9 @@ public class MediaLibrary {
             HashMap<String, Media> existingMedias = mDBManager.getMedias(mContext);

             // list of all added files
-            HashSet<File> addedFiles = new HashSet<File>();
+            HashSet<String> addedLocations = new HashSet<String>();

-            // clear all old item
+            // clear all old items
             mItemList.clear();

             MediaItemFilter mediaFileFilter = new MediaItemFilter();
@@ -221,18 +221,17 @@ public class MediaLibrary {
                         File file = f[i];

                         if (file.isFile()) {
-
                             MainActivity.sendTextInfo(mContext, file.getName(), count, total);
                             count++;
-
-                            if (existingMedias.containsKey(file.getPath())) {
+                            String fileURI = Util.PathToURI(file.getPath());
+                            if (existingMedias.containsKey(fileURI)) {
                                 /** only add file if it is not already in the
                                  * list. eg. if user select an subfolder as well
                                  */
-                                if (!addedFiles.contains(file)) {
+                                if (!addedLocations.contains(fileURI)) {
                                     // get existing media item from database
-                                    mItemList.add(existingMedias.get(file.getPath()));
-                                    addedFiles.add(file);
+                                    mItemList.add(existingMedias.get(fileURI));
+                                    addedLocations.add(fileURI);
                                 }
                             } else {
                                 // create new media item
@@ -252,11 +251,11 @@ public class MediaLibrary {
             }

             // remove file from database
-            for (File file : addedFiles) {
-                existingMedias.remove(file.getPath());
+            for (String fileURI : addedLocations) {
+                existingMedias.remove(fileURI);
             }
-            for (String path : existingMedias.keySet()) {
-                mDBManager.removeMedia(path);
+            for (String existingMedia : existingMedias.keySet()) {
+                mDBManager.removeMedia(existingMedia);
             }

             // hide progressbar in header
diff --git a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
index 3e418fb..09eb48a 100644
--- a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
+++ b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
@@ -122,7 +122,7 @@ public class ThumbnailerManager extends Thread {
             // Get the thumbnail.
             Bitmap thumbnail = Bitmap.createBitmap(width, height, Config.ARGB_8888);
             //Log.i(TAG, "create new bitmap for: " + item.getName());
-            byte[] b = mLibVlc.getThumbnail(item.getPath(), width, height);
+            byte[] b = mLibVlc.getThumbnail(item.getLocation(), width, height);

             if (b == null) // We were not able to create a thumbnail for this item.
                 continue;
diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index bfdec1a..1327cd4 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -20,6 +20,7 @@

 package org.videolan.vlc;

+import java.io.File;
 import java.lang.reflect.Field;
 import java.text.DecimalFormat;

@@ -39,6 +40,20 @@ public class Util {
         toaster(context, stringId, Toast.LENGTH_SHORT);
     }

+    public static File URItoFile(String URI) {
+        return new File(URI.replace("file://", "file:"));
+    }
+
+    public static String PathToURI(String path) {
+        String URI;
+        try {
+            URI = LibVLC.getInstance().nativeToURI(path);
+        } catch (LibVlcException e) {
+            URI = "";
+        }
+        return URI;
+    }
+
     /**
      * Convert time to a string
      * @param millis e.g.time/length from file
diff --git a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
index 0176cbd..a5d86d8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SearchActivity.java
@@ -122,9 +122,9 @@ public class SearchActivity extends ListActivity {
                 continue;
             boolean add = true;
             String name = item.getTitle().toLowerCase();
-            String path = item.getPath().toLowerCase();
+            String MRL = item.getLocation().toLowerCase();
             for (int k = 0; k < keys.length; k++) {
-                if (!(name.contains(keys[k].toLowerCase()) || path.contains(keys[k].toLowerCase()))) {
+                if (!(name.contains(keys[k].toLowerCase()) || MRL.contains(keys[k].toLowerCase()))) {
                     add = false;
                     break;
                 }
@@ -252,15 +252,15 @@ public class SearchActivity extends ListActivity {
             Intent intent;
             if (item.getType() == Media.TYPE_VIDEO) {
                 intent = new Intent(this, VideoPlayerActivity.class);
-                intent.putExtra("filePath", item.getPath());
+                intent.putExtra("itemLocation", item.getLocation());
             } else {
                 ArrayList<String> arr = new ArrayList<String>();
                 for (int i = 0; i < getListAdapter().getCount(); i++) {
                     Media audioItem = (Media) getListAdapter().getItem(i);
                     if (audioItem.getType() == Media.TYPE_AUDIO)
-                        arr.add(audioItem.getPath());
+                        arr.add(audioItem.getLocation());
                 }
-                AudioServiceController.getInstance().load(arr, arr.indexOf(item.getPath()));
+                AudioServiceController.getInstance().load(arr, arr.indexOf(item.getLocation()));
                 intent = new Intent(this, AudioPlayerActivity.class);
             }
             startActivity(intent);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
index 0e9a76f..8cd2c02 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserActivity.java
@@ -120,7 +120,7 @@ public class AudioBrowserActivity extends Activity implements ISortable {
     OnItemClickListener songListener = new OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> av, View v, int p, long id) {
-            mAudioController.load(mSongsAdapter.getPaths(), p);
+            mAudioController.load(mSongsAdapter.getLocations(), p);
             Intent intent = new Intent(AudioBrowserActivity.this, AudioPlayerActivity.class);
             intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
             startActivity(intent);
@@ -165,14 +165,14 @@ public class AudioBrowserActivity extends Activity implements ISortable {

         if (play_all) {
             start_position = menuInfo.position;
-            medias = mSongsAdapter.getPaths();
+            medias = mSongsAdapter.getLocations();
         }
         else {
             start_position = 0;
             switch (mFlingViewGroup.getPosition())
             {
                 case MODE_SONG:
-                    medias = mSongsAdapter.getPath(menuInfo.position);
+                    medias = mSongsAdapter.getLocation(menuInfo.position);
                     break;
                 case MODE_ARTIST:
                     medias = mArtistsAdapter.getPlaylist(menuInfo.position);
@@ -247,9 +247,9 @@ public class AudioBrowserActivity extends Activity implements ISortable {
     }
     };

-    private Comparator<Media> byPath = new Comparator<Media>() {
+    private Comparator<Media> byMRL = new Comparator<Media>() {
         public int compare(Media m1, Media m2) {
-            return String.CASE_INSENSITIVE_ORDER.compare(m1.getFile().getPath(), m2.getFile().getPath());
+            return String.CASE_INSENSITIVE_ORDER.compare(m1.getLocation(), m2.getLocation());
         };
     };

@@ -265,7 +265,7 @@ public class AudioBrowserActivity extends Activity implements ISortable {
         public int compare(Media m1, Media m2) {
             int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getAlbum(), m2.getAlbum());
             if (res == 0)
-                res = byPath.compare(m1, m2);
+                res = byMRL.compare(m1, m2);
             return res;
         };
     };
@@ -301,7 +301,7 @@ public class AudioBrowserActivity extends Activity implements ISortable {
             break;
         case SORT_BY_TITLE:
         default:
-            Collections.sort(audioList, byPath);
+            Collections.sort(audioList, byMRL);
             break;
         }
         if(mSortReverse) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
index 1a3a68a..c424e12 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
@@ -106,7 +106,7 @@ public class AudioListActivity extends ListActivity {

     @Override
     protected void onListItemClick(ListView l, View v, int position, long id) {
-        mAudioController.load(mSongsAdapter.getPaths(), position);
+        mAudioController.load(mSongsAdapter.getLocations(), position);
         Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
         intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         startActivity(intent);
@@ -136,11 +136,11 @@ public class AudioListActivity extends ListActivity {

         if (play_all) {
             start_position = menuInfo.position;
-            medias = mSongsAdapter.getPaths();
+            medias = mSongsAdapter.getLocations();
         }
         else {
             start_position = 0;
-            medias = mSongsAdapter.getPath(menuInfo.position);
+            medias = mSongsAdapter.getLocation(menuInfo.position);
         }
         if (play_append)
             mAudioController.append(medias);
@@ -168,9 +168,9 @@ public class AudioListActivity extends ListActivity {
         }
     };

-    private Comparator<Media> byPath = new Comparator<Media>() {
+    private Comparator<Media> byMRL = new Comparator<Media>() {
         public int compare(Media m1, Media m2) {
-            return String.CASE_INSENSITIVE_ORDER.compare(m1.getFile().getPath(), m2.getFile().getPath());
+            return String.CASE_INSENSITIVE_ORDER.compare(m1.getLocation(), m2.getLocation());
         };
     };

@@ -211,7 +211,7 @@ public class AudioListActivity extends ListActivity {
                 break;
             case SORT_BY_TITLE:
             default:
-                Collections.sort(audioList, byPath);
+                Collections.sort(audioList, byMRL);
                 break;
         }
         if (mSortReverse) {
@@ -220,7 +220,7 @@ public class AudioListActivity extends ListActivity {

         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
-            if (currentItem != null && currentItem.equals(media.getPath()))
+            if (currentItem != null && currentItem.equals(media.getLocation()))
                 currentIndex = i;
             mSongsAdapter.add(media);
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
index 530cf62..c383a70 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
@@ -102,7 +102,7 @@ public class AudioPlaylistAdapter extends ArrayAdapter<String> {
         if (position >= 0 && position < mTitles.size()) {
             List<Media> mediaList = mPlaylists.get(mTitles.get(position));
             for (int i = 0; i < mediaList.size(); i++) {
-                playlist.add(mediaList.get(i).getPath());
+                playlist.add(mediaList.get(i).getLocation());
             }
         }
         return playlist;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
index b9d2c4a..1f95669 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
@@ -82,19 +82,19 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
         return v;
     }

-    public List<String> getPath(int position) {
-        List<String> paths = new ArrayList<String>();
+    public List<String> getLocation(int position) {
+        List<String> locations = new ArrayList<String>();
         if (position >= 0 && position < mMediaList.size())
-            paths.add(mMediaList.get(position).getPath());
-        return paths;
+            locations.add(mMediaList.get(position).getLocation());
+        return locations;
     }

-    public List<String> getPaths() {
-        List<String> paths = new ArrayList<String>();
+    public List<String> getLocations() {
+        List<String> locations = new ArrayList<String>();
         for (int i = 0; i < mMediaList.size(); i++) {
-            paths.add(mMediaList.get(i).getPath());
+            locations.add(mMediaList.get(i).getLocation());
         }
-        return paths;
+        return locations;
     }

     static class ViewHolder {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java
index bad0544..4835a72 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoActivity.java
@@ -52,10 +52,10 @@ public class MediaInfoActivity extends ListActivity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.media_info);
-        String path = getIntent().getExtras().getString("filePath");
-        if (path == null)
+        String MRL = getIntent().getExtras().getString("itemLocation");
+        if (MRL == null)
             return;
-        mItem = MediaLibrary.getInstance(this).getMediaItem(path);
+        mItem = MediaLibrary.getInstance(this).getMediaItem(MRL);

         // set title
         TextView titleView = (TextView) findViewById(R.id.title);
@@ -81,7 +81,7 @@ public class MediaInfoActivity extends ListActivity {
                 return;
             }

-            mTracks = mLibVlc.readTracksInfo(mItem.getPath());
+            mTracks = mLibVlc.readTracksInfo(mItem.getLocation());
             mHandler.sendEmptyMessage(NEW_TEXT);

             int width = Math.min(getWindowManager().getDefaultDisplay().getWidth(),
@@ -91,7 +91,7 @@ public class MediaInfoActivity extends ListActivity {
             // Get the thumbnail.
             mImage = Bitmap.createBitmap(width, height, Config.ARGB_8888);

-            byte[] b = mLibVlc.getThumbnail(mItem.getPath(), width, height);
+            byte[] b = mLibVlc.getThumbnail(mItem.getLocation(), width, height);

             if (b == null) // We were not able to create a thumbnail for this item.
                 return;
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListActivity.java
index c038d18..e567baf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListActivity.java
@@ -103,7 +103,7 @@ public class VideoListActivity extends ListActivity implements ISortable {

         Media item = (Media) getListAdapter().getItem(position);
         Intent intent = new Intent(this, VideoPlayerActivity.class);
-        intent.putExtra("filePath", item.getPath());
+        intent.putExtra("itemLocation", item.getLocation());
         startActivity(intent);
         super.onListItemClick(l, v, position, id);
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index b230b42..6b1c0dc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -46,7 +46,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
     public final static int SORT_BY_LENGTH = 1;
     private int mSortDirection = 1;
     private int mSortBy = SORT_BY_TITLE;
-    private String mLastPath;
+    private String mLastMRL;

     public VideoListAdapter(Context context, int textViewResourceId) {
         super(context, textViewResourceId);
@@ -62,8 +62,8 @@ public class VideoListAdapter extends ArrayAdapter<Media>
         }
     }

-    public void setLastMedia(String lastPath) {
-        mLastPath = lastPath;
+    public void setLastMedia(String lastMRL) {
+        mLastMRL = lastMRL;
     }

     public void sortBy(int sortby) {
@@ -144,7 +144,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
             holder.thumbnail.setImageBitmap(thumbnail);
         }

-        holder.title.setTextColor(media.getPath().equals(mLastPath) ? Color.RED : Color.WHITE);
+        holder.title.setTextColor(media.getLocation().equals(mLastMRL) ? Color.RED : Color.WHITE);
         holder.more.setTag(media);
         holder.more.setOnClickListener(moreClickListener);

@@ -157,7 +157,7 @@ public class VideoListAdapter extends ArrayAdapter<Media>
         public void onClick(View v) {
             Media item = (Media) v.getTag();
             Intent intent = new Intent(getContext(), MediaInfoActivity.class);
-            intent.putExtra("filePath", item.getPath());
+            intent.putExtra("itemLocation", item.getLocation());
             getContext().startActivity(intent);
         }
     };
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 26db89f..0506715 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -786,36 +786,36 @@ public class VideoPlayerActivity extends Activity {
      *
      */
     private void load() {
-        String path = null;
+        String location = null;
         String title = null;
-        String lastPath = null;
+        String lastLocation = null;
         long lastTime = 0;
         SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);

         if (getIntent().getAction() != null
                 && getIntent().getAction().equals(Intent.ACTION_VIEW)) {
             /* Started from external application */
-            path = getIntent().getDataString();
+            location = getIntent().getDataString();
         } else {
             /* Started from VideoListActivity */
-            path = getIntent().getExtras().getString("filePath");
+            location = getIntent().getExtras().getString("itemLocation");
         }

-        if (path != null && path.length() > 0) {
-            mLibVLC.readMedia(path);
+        if (location != null && location.length() > 0) {
+            mLibVLC.readMedia(location);
             if (!mWakeLock.isHeld())
                 mWakeLock.acquire();

             // Save media for next time, and restore position if it's the same one as before
-            lastPath = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
+            lastLocation = preferences.getString(PreferencesActivity.LAST_MEDIA, null);
             lastTime = preferences.getLong(PreferencesActivity.LAST_TIME, 0);
             SharedPreferences.Editor editor = preferences.edit();
-            editor.putString(PreferencesActivity.LAST_MEDIA, path);
+            editor.putString(PreferencesActivity.LAST_MEDIA, location);
             editor.commit();
-            if (lastTime > 0 && path.equals(lastPath))
+            if (lastTime > 0 && location.equals(lastLocation))
                 mLibVLC.setTime(lastTime);

-            title = new File(path).getName();
+            title = new File(location).getName();
             int dotIndex = title.lastIndexOf('.');
             if (dotIndex != -1)
                 title = title.substring(0, dotIndex);
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
index eab36df..4525d94 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
@@ -29,7 +29,7 @@ interface IAudioService {
     void previous();
     void shuffle();
     void setTime(long time);
-    String getCurrentMediaPath();
+    String getCurrentMediaLocation();
     void load(in List<String> mediaPathList, int position);
     void append(in List<String> mediaPathList);
     List<String> getItems();
--
1.7.5.4



More information about the Android mailing list