[Android] Add openMediaNoUi, for non-Activity contexts

Geoffrey Métais git at videolan.org
Mon Dec 21 17:21:51 CET 2015


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 10 16:18:21 2015 +0100| [d628a8681ed711eacf8700ef60c8f4dbadaac6fd] | committer: Geoffrey Métais

Add openMediaNoUi, for non-Activity contexts

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

 .../src/org/videolan/vlc/media/MediaUtils.java     | 32 ++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
index bf9511f..8214345 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
@@ -10,6 +10,7 @@ import android.support.v4.content.LocalBroadcastManager;
 import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.gui.video.VideoPlayerActivity;
 import org.videolan.vlc.util.FileUtils;
 import org.videolan.vlc.util.Strings;
 
@@ -42,6 +43,20 @@ public class MediaUtils {
         });
     }
 
+    public static void openMediaNoUi(final Context context, final MediaWrapper media){
+        if (media == null)
+            return;
+        if (media.getType() == MediaWrapper.TYPE_VIDEO)
+            VideoPlayerActivity.start(context, media.getUri(), media.getTitle());
+        else
+            new BaseCallBack(context) {
+                @Override
+                public void onConnected(PlaybackService service) {
+                    service.load(media);
+                }
+            };
+    }
+
     public static void openList(final Context context, final List<MediaWrapper> list, final int position){
         new DialogCallback(context, new DialogCallback.Runnable() {
             @Override
@@ -128,9 +143,22 @@ public class MediaUtils {
         }
     }
 
-    private static class DialogCallback implements PlaybackService.Client.Callback {
+    private static abstract class BaseCallBack implements PlaybackService.Client.Callback {
+        protected PlaybackService.Client mClient;
+
+        private BaseCallBack(Context context) {
+            mClient = new PlaybackService.Client(context, this);
+            mClient.connect();
+        }
+
+        protected BaseCallBack() {}
+
+        @Override
+        public void onDisconnected() {}
+    }
+
+    private static class DialogCallback extends BaseCallBack {
         private final ProgressDialog dialog;
-        final private PlaybackService.Client mClient;
         final private Runnable mRunnable;
 
         private interface Runnable {



More information about the Android mailing list