[Android] [PATCH] Use MRLs and libvlc_media_new_location everywhere

Jean-Baptiste Kempf jb at videolan.org
Fri Mar 16 18:08:03 CET 2012


This crashes for me, with my old database.
So, I cleaned it.

And then it blocks when rescanning my collection, by using wrong 
encoding on some songs with Unicode names...

On 14/03/2012 17:06, Edward Wang wrote:
> ---
>   Update as of March 14, 2012 with all fixes
>
>   vlc-android/jni/libvlcjni.c                        |   18 ++--
>   vlc-android/src/org/videolan/vlc/AudioService.java |   16 ++--
>   .../src/org/videolan/vlc/DatabaseManager.java      |   59 +++++++++------
>   vlc-android/src/org/videolan/vlc/LibVLC.java       |   18 ++--
>   vlc-android/src/org/videolan/vlc/Media.java        |   81 ++++++++++++++------
>   vlc-android/src/org/videolan/vlc/MediaLibrary.java |   25 +++---
>   .../src/org/videolan/vlc/ThumbnailerManager.java   |    2 +-
>   vlc-android/src/org/videolan/vlc/Util.java         |   31 ++++++++
>   .../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 +-
>   18 files changed, 214 insertions(+), 136 deletions(-)
>
> diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
> index ee8bf31..4b84f5e 100644
> --- a/vlc-android/jni/libvlcjni.c
> +++ b/vlc-android/jni/libvlcjni.c
> @@ -34,13 +34,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;
>
> @@ -444,10 +444,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 +558,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 +573,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..3b9cd13 100644
> --- a/vlc-android/src/org/videolan/vlc/DatabaseManager.java
> +++ b/vlc-android/src/org/videolan/vlc/DatabaseManager.java
> @@ -22,6 +22,8 @@ package org.videolan.vlc;
>
>   import java.io.ByteArrayOutputStream;
>   import java.io.File;
> +import java.net.URI;
> +import java.net.URISyntaxException;
>   import java.text.SimpleDateFormat;
>   import java.util.ArrayList;
>   import java.util.Date;
> @@ -51,7 +53,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 +117,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 +221,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 +261,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 +295,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);
> @@ -305,12 +307,19 @@ public class DatabaseManager {
>                           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),
> -                            picture, cursor.getString(4),
> -                            cursor.getString(5), cursor.getString(6),
> -                            cursor.getString(7));
> -                    medias.put(media.getPath(), media);
> +                    try {
> +                        Media media = new Media(context, new File(Util.VLCPathToURI(cursor.getString(8))), 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.getLocation(), media);
> +                    } catch (URISyntaxException e) {
> +                        // URISyntax
> +                        // Exception: Cannot happen
> +                        // But Java forced me
> +                    }
> +
>                       picture = null;
>                       count++;
>                   } while (cursor.moveToNext());
> @@ -323,7 +332,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 +351,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()) {
>
> @@ -352,21 +361,25 @@ public class DatabaseManager {
>                   picture = BitmapFactory.decodeByteArray(blob, 0, blob.length);
>               }
>
> -            media = new Media(context, new File(path), cursor.getLong(0),
> -                    cursor.getLong(1), cursor.getInt(2),
> -                    picture, cursor.getString(4),
> -                    cursor.getString(5), cursor.getString(6),
> -                    cursor.getString(7));
> +            try {
> +                media = new Media(context, new File(Util.VLCPathToURI(location)), cursor.getLong(0),
> +                        cursor.getLong(1), cursor.getInt(2),
> +                        picture, cursor.getString(4),
> +                        cursor.getString(5), cursor.getString(6),
> +                        cursor.getString(7));
> +            } catch (URISyntaxException e) {
> +                //not possible, but java requires it
> +            }
>           }
>           cursor.close();
>           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 +392,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 e3f7682..9bda5c7 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 true if there is a video track in the file
>        */
> -    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);
>
> @@ -361,7 +361,7 @@ public class LibVLC {
>       /**
>        * Return true if there is a video track in the file
>        */
> -    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..e34300f 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,13 @@ public class Media implements Comparable<Media>  {
>       private String mEncodedBy;
>       private String mTrackID;
>
> -    private File mFile;
> +    private String mLocation;
> +    private String mFilename;
> +    /**
> +     * To maintain compatibility in a couple of places
> +     * Only used internally now
> +     */
> +    private File mFile_internal;
>       private long mTime = 0;
>       private long mLength = 0;
>       private int mType;
> @@ -71,19 +79,33 @@ 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) {
> +        mFile_internal = null;
> +        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 +130,30 @@ 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);
> +        }
> +    }
> +
> +    /**
> +     * 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.FixURI(file.toURI()), true);
> +        mFile_internal = file;
> +        mFilename = mFile_internal.getName().substring(0, mFile_internal.getName().lastIndexOf('.'));
>       }
>
>       public Media(Context context, File file, long time, long length, int type,
>               Bitmap picture, String title, String artist, String genre, String album) {
> -        mFile = file;
> +        mFile_internal = file;
> +        mLocation = Util.FixURI(file.toURI().toString());
> +        mFilename = mFile_internal.getName().substring(0, mFile_internal.getName().lastIndexOf('.'));
>           mTime = time;
>           mLength = length;
>           mType = type;
> @@ -135,12 +173,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 +182,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 +216,16 @@ 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
> -            return mTitle;
> +        /* should never happen */
> +        assert (mTitle != null);
> +        return mTitle;
>       }
>
>       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..768105c 100644
> --- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
> +++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
> @@ -23,6 +23,8 @@ package org.videolan.vlc;
>   import java.io.File;
>   import java.io.FileFilter;
>   import java.lang.Thread.State;
> +import java.net.URI;
> +import java.net.URISyntaxException;
>   import java.util.ArrayList;
>   import java.util.Arrays;
>   import java.util.HashMap;
> @@ -132,10 +134,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 +185,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 +223,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.FixURI(file.toURI().toString());
> +                            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,8 +253,8 @@ 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);
> 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..509e21e 100644
> --- a/vlc-android/src/org/videolan/vlc/Util.java
> +++ b/vlc-android/src/org/videolan/vlc/Util.java
> @@ -21,6 +21,8 @@
>   package org.videolan.vlc;
>
>   import java.lang.reflect.Field;
> +import java.net.URI;
> +import java.net.URISyntaxException;
>   import java.text.DecimalFormat;
>
>   import android.content.Context;
> @@ -40,6 +42,35 @@ public class Util {
>       }
>
>       /**
> +     * A function to fix up the broken Java URI format
> +     * LibVLC expects the file:///sdcard/... format, but by default
> +     * Java gives the file:/sdcard format, which angers LibVLC
> +     * Reference: http://stackoverflow.com/questions/1131273/java-file-touri-tourl-on-windows-file
> +     *
> +     * @param javaURI The URI returned by Java
> +     * @return Fixed URI for use by LibVLC
> +     */
> +    public static String FixURI(String javaURI) {
> +        return javaURI.replace("file:", "file://");
> +    }
> +
> +    public static String FixURI(URI uri) {
> +        return FixURI(uri.toString());
> +    }
> +
> +    /**
> +     * Function to convert a LibVLC path back to a Java URI
> +     * Converts the file:///sdcard format back to the file:/sdcard format
> +     *
> +     * @param path the libvlc path (file:///)
> +     * @return the Java URI (file:/)
> +     * @throws URISyntaxException
> +     */
> +    public static URI VLCPathToURI(String path) throws URISyntaxException {
> +        return new URI(path.replace("file://", "file:"));
> +    }
> +
> +    /**
>        * Convert time to a string
>        * @param millis e.g.time/length from file
>        * @return formated string (hh:)mm:ss
> 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();


-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device


More information about the Android mailing list