[Android] libvlc/MediaList: get rid of MediaHolder and getMediaOptions

Thomas Guillem git at videolan.org
Wed Dec 31 18:03:49 CET 2014


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Dec 31 12:36:50 2014 +0100| [e43bc1223bc3d4ba535002214c0b7736c3a48bb3] | committer: Thomas Guillem

libvlc/MediaList: get rid of MediaHolder and getMediaOptions

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

 libvlc/src/org/videolan/libvlc/LibVLC.java         |    6 ++-
 libvlc/src/org/videolan/libvlc/MediaList.java      |   53 ++++----------------
 .../src/org/videolan/vlc/audio/AudioService.java   |    4 +-
 3 files changed, 17 insertions(+), 46 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/LibVLC.java b/libvlc/src/org/videolan/libvlc/LibVLC.java
index 13c6d25..1a58290 100644
--- a/libvlc/src/org/videolan/libvlc/LibVLC.java
+++ b/libvlc/src/org/videolan/libvlc/LibVLC.java
@@ -576,7 +576,9 @@ public class LibVLC {
         String mrl = mMediaList.getMRL(position);
         if (mrl == null)
             return;
-        String[] options = mMediaList.getMediaOptions(position);
+
+        final Media media = mMediaList.getMedia(position);
+        String[] options = getMediaOptions(media);
         mInternalMediaPlayerIndex = position;
         playMRL(mrl, options);
     }
@@ -588,7 +590,7 @@ public class LibVLC {
      */
     public void playMRL(String mrl) {
         // index=-1 will return options from libvlc instance without relying on MediaList
-        String[] options = mMediaList.getMediaOptions(-1);
+        String[] options = getMediaOptions(false, false);
         mInternalMediaPlayerIndex = 0;
         playMRL(mrl, options);
     }
diff --git a/libvlc/src/org/videolan/libvlc/MediaList.java b/libvlc/src/org/videolan/libvlc/MediaList.java
index 7888f6f..228433e 100644
--- a/libvlc/src/org/videolan/libvlc/MediaList.java
+++ b/libvlc/src/org/videolan/libvlc/MediaList.java
@@ -30,29 +30,15 @@ import android.os.Bundle;
 public class MediaList {
     private static final String TAG = "VLC/LibVLC/MediaList";
 
-    /* Since the libvlc_media_t is not created until the media plays, we have
-     * to cache them here. */
-    private static class MediaHolder {
-        Media m;
-        boolean noVideo; // default false
-        boolean noHardwareAcceleration; // default false
-
-        public MediaHolder(Media media) {
-            m = media; noVideo = false; noHardwareAcceleration = false;
-        }
-        public MediaHolder(Media m_, boolean noVideo_, boolean noHardwareAcceleration_) {
-            m = m_; noVideo = noVideo_; noHardwareAcceleration = noHardwareAcceleration_;
-        }
-    }
 
     /* TODO: add locking */
-    private ArrayList<MediaHolder> mInternalList;
+    private ArrayList<Media> mInternalList;
     private LibVLC mLibVLC; // Used to create new objects that require a libvlc instance
     private EventHandler mEventHandler;
 
     public MediaList(LibVLC libVLC) {
         mEventHandler = new EventHandler(); // used in init() below to fire events at the correct targets
-        mInternalList = new ArrayList<MediaHolder>();
+        mInternalList = new ArrayList<Media>();
         mLibVLC = libVLC;
     }
 
@@ -68,14 +54,7 @@ public class MediaList {
         add(new Media(mLibVLC, mrl));
     }
     public void add(Media media) {
-        add(media, false, false);
-    }
-    public void add(Media media, boolean noVideo) {
-        add(media, noVideo, false);
-    }
-    public void add(Media media, boolean noVideo, boolean noHardwareAcceleration) {
-        mInternalList.add(new MediaHolder(media, noVideo, noHardwareAcceleration));
-        signal_list_event(EventHandler.CustomMediaListItemAdded, mInternalList.size() - 1, media.getLocation());
+        mInternalList.add(media);
     }
 
     /**
@@ -84,7 +63,7 @@ public class MediaList {
     public void clear() {
         // Signal to observers of media being deleted.
         for(int i = 0; i < mInternalList.size(); i++) {
-            signal_list_event(EventHandler.CustomMediaListItemDeleted, i, mInternalList.get(i).m.getLocation());
+            signal_list_event(EventHandler.CustomMediaListItemDeleted, i, mInternalList.get(i).getLocation());
         }
         mInternalList.clear();
     }
@@ -128,7 +107,7 @@ public class MediaList {
         insert(position, new Media(mLibVLC, mrl));
     }
     public void insert(int position, Media media) {
-        mInternalList.add(position, new MediaHolder(media));
+        mInternalList.add(position, media);
         signal_list_event(EventHandler.CustomMediaListItemAdded, position, media.getLocation());
     }
 
@@ -144,7 +123,7 @@ public class MediaList {
               && endPosition >= 0 && endPosition <= mInternalList.size()))
             throw new IndexOutOfBoundsException("Indexes out of range");
 
-        MediaHolder toMove = mInternalList.get(startPosition);
+        Media toMove = mInternalList.get(startPosition);
         mInternalList.remove(startPosition);
         if (startPosition >= endPosition)
             mInternalList.add(endPosition, toMove);
@@ -159,14 +138,14 @@ public class MediaList {
     public void remove(int position) {
         if (!isValid(position))
             return;
-        String uri = mInternalList.get(position).m.getLocation();
+        String uri = mInternalList.get(position).getLocation();
         mInternalList.remove(position);
         signal_list_event(EventHandler.CustomMediaListItemDeleted, position, uri);
     }
 
     public void remove(String location) {
         for (int i = 0; i < mInternalList.size(); ++i) {
-            String uri = mInternalList.get(i).m.getLocation();
+            String uri = mInternalList.get(i).getLocation();
             if (uri.equals(location)) {
                 mInternalList.remove(i);
                 signal_list_event(EventHandler.CustomMediaListItemDeleted, i, uri);
@@ -182,7 +161,7 @@ public class MediaList {
     public Media getMedia(int position) {
         if (!isValid(position))
             return null;
-        return mInternalList.get(position).m;
+        return mInternalList.get(position);
     }
 
     /**
@@ -192,19 +171,7 @@ public class MediaList {
     public String getMRL(int position) {
         if (!isValid(position))
             return null;
-        return mInternalList.get(position).m.getLocation();
-    }
-
-    public String[] getMediaOptions(int position) {
-        boolean noHardwareAcceleration = false;
-        boolean noVideo = false;
-        if (isValid(position))
-        {
-            noHardwareAcceleration = mInternalList.get(position).noHardwareAcceleration;
-            noVideo = mInternalList.get(position).noVideo;
-        }
-
-        return mLibVLC.getMediaOptions(noHardwareAcceleration, noVideo);
+        return mInternalList.get(position).getLocation();
     }
 
     public EventHandler getEventHandler() {
diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index 9063780..1055716 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -1201,7 +1201,9 @@ public class AudioService extends Service {
                     Log.v(TAG, "Creating on-the-fly Media object for " + location);
                     media = new Media(mLibVLC, location);
                 }
-                mediaList.add(media, noVideo);
+                if (noVideo)
+                    media.addFlags(Media.FLAG_NO_VIDEO);
+                mediaList.add(media);
             }
 
             if (mLibVLC.getMediaList().size() == 0) {



More information about the Android mailing list