[Android] MediaBrowser: use MediaDiscoverer.getServices

Thomas Guillem git at videolan.org
Thu Feb 11 15:39:48 CET 2016


vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Feb 11 15:37:58 2016 +0100| [76f6f2f7267f2186e38cddd2f5d3adf28d20d979] | committer: Thomas Guillem

MediaBrowser: use MediaDiscoverer.getServices

> https://code.videolan.org/videolan/vlc-android/commit/76f6f2f7267f2186e38cddd2f5d3adf28d20d979
---

 .../src/org/videolan/libvlc/util/MediaBrowser.java | 37 ++++++++++------------
 .../vlc/gui/browser/NetworkBrowserFragment.java    |  2 +-
 .../vlc/gui/tv/browser/BrowserGridFragment.java    |  2 +-
 .../vlc/gui/tv/browser/NetworkBrowserFragment.java |  2 +-
 vlc-android/src/org/videolan/vlc/util/Util.java    |  5 ---
 5 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java b/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
index aacf45c..1719650 100644
--- a/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
+++ b/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
@@ -22,6 +22,7 @@ package org.videolan.libvlc.util;
 
 import android.net.Uri;
 import android.support.annotation.MainThread;
+import android.util.Log;
 
 import java.util.ArrayList;
 
@@ -31,18 +32,7 @@ import org.videolan.libvlc.MediaDiscoverer;
 import org.videolan.libvlc.MediaList;
 
 public class MediaBrowser {
-    private static final String TAG = "LibVLC/util/MediaBrowser";
-
-    public enum Discover {
-        UPNP("upnp"),
-        SMB("dsm")
-        ;
-
-        private final String str;
-        Discover(String str) {
-            this.str = str;
-        }
-    }
+    private static final String TAG = "MediaBrowser";
 
     private final LibVLC mLibVlc;
     private final ArrayList<MediaDiscoverer> mMediaDiscoverers = new ArrayList<MediaDiscoverer>();
@@ -134,24 +124,29 @@ public class MediaBrowser {
     }
 
     /**
-     * Discover networks shares using a list of Discoverers
+     * Discover all networks shares
      */
     @MainThread
-    public void discoverNetworkShares(Discover discovers[]) {
+    public void discoverNetworkShares() {
         reset();
-        for (Discover discover : discovers)
-            startMediaDiscoverer(discover.str);
+        final MediaDiscoverer.Service services[] =
+                MediaDiscoverer.getServices(mLibVlc, MediaDiscoverer.Service.Category.Lan);
+        if (services == null)
+            return;
+        for (MediaDiscoverer.Service service : services) {
+            Log.i(TAG, "starting " + service.name + " discover (" + service.longName + ")");
+            startMediaDiscoverer(service.name);
+        }
     }
 
     /**
      * Discover networks shares using a specified Discoverer
-     * @param discovererName
+     * @param serviceName see {@link MediaDiscoverer.Service.Category#name}
      */
     @MainThread
-    public void discoverNetworkShares(Discover discover) {
-        Discover discovers[] = new Discover[1];
-        discovers[0] = discover;
-        discoverNetworkShares(discovers);
+    public void discoverNetworkShares(String serviceName) {
+        reset();
+        startMediaDiscoverer(serviceName);
     }
 
     /**
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
index dbcda2f..22c5985 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.java
@@ -113,7 +113,7 @@ public class NetworkBrowserFragment extends BaseBrowserFragment implements View.
     protected void browseRoot() {
         updateFavorites();
         mAdapter.setTop(mAdapter.getItemCount());
-        mMediaBrowser.discoverNetworkShares(Util.NETWORK_DISCOVER_LIST);
+        mMediaBrowser.discoverNetworkShares();
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java
index 928d18b..a06eff3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BrowserGridFragment.java
@@ -74,7 +74,7 @@ public class BrowserGridFragment extends GridFragment implements MediaBrowser.Ev
                 if (mUri != null)
                     mMediaBrowser.browse(mUri, true);
                 else
-                    mMediaBrowser.discoverNetworkShares(Util.NETWORK_DISCOVER_LIST);
+                    mMediaBrowser.discoverNetworkShares();
                 ((BrowserActivityInterface)getActivity()).showProgress(true);
             }
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
index 2fa273e..70da50a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/NetworkBrowserFragment.java
@@ -36,7 +36,7 @@ public class NetworkBrowserFragment extends MediaSortedFragment {
     public static final String TAG = "VLC/NetworkBrowserFragment";
 
     protected void browseRoot() {
-        mMediaBrowser.discoverNetworkShares(Util.NETWORK_DISCOVER_LIST);
+        mMediaBrowser.discoverNetworkShares();
     }
 
     protected void addMedia(Media media){
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index f15cd65..13f3541 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -88,9 +88,4 @@ public class Util {
                 PackageManager.MATCH_DEFAULT_ONLY);
         return list.size() > 0;
     }
-
-    public static final MediaBrowser.Discover NETWORK_DISCOVER_LIST[] = new MediaBrowser.Discover[] {
-            MediaBrowser.Discover.UPNP,
-            MediaBrowser.Discover.SMB,
-    };
 }



More information about the Android mailing list