[Android] [PATCH 2/2] MediaBrowser: use MediaDiscoverer.getServices

Thomas Guillem thomas at gllm.fr
Tue Feb 9 15:18:33 CET 2016


---
 .../src/org/videolan/libvlc/util/MediaBrowser.java | 35 +++++++++-------------
 .../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, 17 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..8ccfd4c 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,27 @@ 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);
+        MediaDiscoverer.Service services[] =
+                MediaDiscoverer.getServices(mLibVlc, MediaDiscoverer.Service.Category.Lan);
+        for (MediaDiscoverer.Service service : services) {
+            Log.e(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 5393e09..e4ed7c4 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 SortedBrowserFragment {
     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,
-    };
 }
-- 
2.7.0.rc3



More information about the Android mailing list