[Android] Media: remove a Util.getLibVlcInstance() call

Edward Wang git at videolan.org
Mon Nov 4 04:45:24 CET 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sun Nov  3 22:45:10 2013 -0500| [9788dc72f46bd5d8575b01ba89bb63134d1dd629] | committer: Edward Wang

Media: remove a Util.getLibVlcInstance() call

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

 vlc-android/src/org/videolan/libvlc/MediaList.java |    4 ++--
 vlc-android/src/org/videolan/vlc/AudioService.java |    4 ++--
 vlc-android/src/org/videolan/vlc/Media.java        |   23 ++++++++------------
 vlc-android/src/org/videolan/vlc/MediaLibrary.java |   11 +++++++++-
 .../src/org/videolan/vlc/gui/DirectoryAdapter.java |    2 +-
 .../vlc/gui/video/VideoPlayerActivity.java         |    2 +-
 6 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/vlc-android/src/org/videolan/libvlc/MediaList.java b/vlc-android/src/org/videolan/libvlc/MediaList.java
index 8c5b58f..d050dce 100644
--- a/vlc-android/src/org/videolan/libvlc/MediaList.java
+++ b/vlc-android/src/org/videolan/libvlc/MediaList.java
@@ -59,7 +59,7 @@ public class MediaList {
     }
 
     public void add(String mrl) {
-        add(new Media(mrl, false));
+        add(new Media(mLibVLC, mrl, false));
     }
     public void add(Media media) {
         add(media, false, false);
@@ -117,7 +117,7 @@ public class MediaList {
     private native void loadPlaylist(LibVLC libvlc_instance, String mrl, ArrayList<String> items);
 
     public void insert(int position, String mrl) {
-        insert(position, new Media(mrl, false));
+        insert(position, new Media(mLibVLC, mrl, false));
     }
     public void insert(int position, Media media) {
         mInternalList.add(position, new MediaHolder(media));
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index fb7f2e4..064b540 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -947,7 +947,7 @@ public class AudioService extends Service {
                         continue;
                     }
                     Log.v(TAG, "Creating on-the-fly Media object for " + location);
-                    media = new Media(location, false);
+                    media = new Media(mLibVLC, location, false);
                 }
                 mediaList.add(media, noVideo);
             }
@@ -1033,7 +1033,7 @@ public class AudioService extends Service {
                         continue;
                     }
                     Log.v(TAG, "Creating on-the-fly Media object for " + location);
-                    media = new Media(location, false);
+                    media = new Media(mLibVLC, location, false);
                 }
                 mLibVLC.getMediaList().add(media);
             }
diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index 9d2797d..6454e23 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -24,7 +24,6 @@ import java.util.HashSet;
 import java.util.Locale;
 
 import org.videolan.libvlc.LibVLC;
-import org.videolan.libvlc.LibVlcException;
 import org.videolan.libvlc.TrackInfo;
 
 import android.content.Context;
@@ -130,24 +129,20 @@ public class Media implements Comparable<Media> {
 
     /**
      * Create a new Media
-     * @param context Application context of the caller
-     * @param media URI
+     * @param libVLC A pointer to the libVLC instance. Should not be NULL
+     * @param URI The URI of the media.
      * @param addToDb Should it be added to the file database?
      */
-    public Media(String URI, Boolean addToDb) {
-        mLocation = URI;
+    public Media(LibVLC libVLC, String URI, Boolean addToDb) {
+        if(libVLC == null)
+            throw new NullPointerException("libVLC was null");
 
-        LibVLC mLibVlc = null;
-        try {
-            mLibVlc = Util.getLibVlcInstance();
-            mType = TYPE_ALL;
+        mLocation = URI;
 
-            TrackInfo[] tracks = mLibVlc.readTracksInfo(mLocation);
+        mType = TYPE_ALL;
+        TrackInfo[] tracks = libVLC.readTracksInfo(mLocation);
 
-            extractTrackInfo(tracks);
-        } catch (LibVlcException e) {
-            e.printStackTrace();
-        }
+        extractTrackInfo(tracks);
 
         if (addToDb) {
             // Add this item to database
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 51ab085..024be4b 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -34,6 +34,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.videolan.libvlc.LibVLC;
+import org.videolan.libvlc.LibVlcException;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.audio.AudioBrowserFragment;
 import org.videolan.vlc.gui.video.VideoGridFragment;
@@ -206,6 +207,14 @@ public class MediaLibrary {
 
         @Override
         public void run() {
+            LibVLC libVlcInstance;
+            try {
+                libVlcInstance = Util.getLibVlcInstance();
+            } catch (LibVlcException e1) {
+                Log.e(TAG, "ERROR: LibVLCException while trying to get instance");
+                return;
+            }
+
             // Initialize variables
             final MediaDatabase DBManager = MediaDatabase.getInstance(VLCApplication.getAppContext());
 
@@ -311,7 +320,7 @@ public class MediaLibrary {
                     } else {
                         mItemListLock.writeLock().lock();
                         // create new media item
-                        mItemList.add(new Media(fileURI, true));
+                        mItemList.add(new Media(libVlcInstance, fileURI, true));
                         mItemListLock.writeLock().unlock();
                     }
                     if (isStopping) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index 2677509..5721d6c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -298,7 +298,7 @@ public class DirectoryAdapter extends BaseAdapter {
         String holderText = "";
         if(selectedNode.isFile()) {
             Log.d(TAG, "Loading media " + selectedNode.name);
-            Media m = new Media(getMediaLocation(position), false);
+            Media m = new Media(LibVLC.getExistingInstance(), getMediaLocation(position), false);
             holder.title.setText(m.getTitle());
             holderText = m.getSubtitle();
         } else
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 eb4c2cc..fdb6456 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1519,7 +1519,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
             mLibVLC.playIndex(savedIndexPosition);
         } else if (mLocation != null && mLocation.length() > 0 && !dontParse) {
             mLibVLC.setMediaList();
-            mLibVLC.getMediaList().add(new Media(mLocation, false));
+            mLibVLC.getMediaList().add(new Media(mLibVLC, mLocation, false));
             savedIndexPosition = mLibVLC.getMediaList().size() - 1;
             mLibVLC.playIndex(savedIndexPosition);
         }



More information about the Android mailing list