[Android] Always Open stream from VideoPlayerActivity

Thomas Guillem git at videolan.org
Thu Jan 22 11:04:04 CET 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jan 21 16:03:36 2015 +0100| [80f7b8ae3f857b694a55074d2c2436292e715348] | committer: Thomas Guillem

Always Open stream from VideoPlayerActivity

And fallback to AudioService if there is no video.

Opening Video from AudioService can't work with the new android_window vout
module because the module need VideoPlayerActivity to be created at open.
Indeed this activity won't be created if the event MediaPlayerVout is not
received, and this event won't be sent if android_window is not opened.

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

 .../src/org/videolan/vlc/audio/AudioService.java   |   21 ----------
 .../vlc/gui/video/VideoPlayerActivity.java         |   40 ++++++--------------
 vlc-android/src/org/videolan/vlc/util/Util.java    |   17 +--------
 3 files changed, 14 insertions(+), 64 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index c088e40..0da3b32 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -515,11 +515,6 @@ public class AudioService extends Service {
                     if (service.mWakeLock.isHeld())
                         service.mWakeLock.release();
                     break;
-                case EventHandler.MediaPlayerVout:
-                    if(msg.getData().getInt("data") > 0) {
-                        service.handleVout();
-                    }
-                    break;
                 case EventHandler.MediaPlayerPositionChanged:
                     float pos = msg.getData().getFloat("data");
                     service.updateWidgetPosition(service, pos);
@@ -611,22 +606,6 @@ public class AudioService extends Service {
         }
     };
 
-    private void handleVout() {
-        if (!hasCurrentMedia())
-            return;
-        Log.i(TAG, "Obtained video track");
-        String title = getCurrentMedia().getTitle();
-        String MRL = mMediaListPlayer.getMediaList().getMRL(mCurrentIndex);
-        int index = mCurrentIndex;
-        mCurrentIndex = -1;
-        mEventHandler.removeHandler(mVlcEventHandler);
-        // Preserve playback when switching to video
-        hideNotification(false);
-
-        // Switch to the video player & don't lose the currently playing stream
-        VideoPlayerActivity.start(VLCApplication.getAppContext(), MRL, title, index, true);
-    }
-
     private void executeUpdate() {
         executeUpdate(true);
     }
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 f3b705a..fd49826 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -721,28 +721,27 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         start(context, location, null, -1, false, false);
     }
 
-    public static void start(Context context, String location, Boolean fromStart) {
-        start(context, location, null, -1, false, fromStart);
+    public static void start(Context context, String location, boolean fromStart) {
+        start(context, location, null, -1, fromStart, false);
     }
 
-    public static void start(Context context, String location, String title, Boolean dontParse) {
-        start(context, location, title, -1, dontParse, false);
+    public static void start(Context context, String location, String title) {
+        start(context, location, title, -1, false, false);
     }
 
-    public static void start(Context context, String location, String title, int position, Boolean dontParse) {
-        start(context, location, title, position, dontParse, false);
+    public static void start(Context context, String location, String title, int position) {
+        start(context, location, title, position, false, false);
     }
 
-    public static void start(Context context, String location, String title, int position, Boolean dontParse, Boolean fromStart) {
+    public static void start(Context context, String location, String title, int position, boolean fromStart, boolean newTask) {
         Intent intent = new Intent(context, VideoPlayerActivity.class);
         intent.setAction(VideoPlayerActivity.PLAY_FROM_VIDEOGRID);
         intent.putExtra("itemLocation", location);
         intent.putExtra("itemTitle", title);
-        intent.putExtra("dontParse", dontParse);
         intent.putExtra("fromStart", fromStart);
         intent.putExtra("itemPosition", position);
 
-        if (dontParse)
+        if (newTask)
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
 
         context.startActivity(intent);
@@ -2240,7 +2239,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     private void loadMedia() {
         mLocation = null;
         String title = getResources().getString(R.string.title);
-        boolean dontParse = false;
         boolean fromStart = false;
         Uri data;
         String itemTitle = null;
@@ -2337,7 +2335,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
                 && getIntent().getExtras() != null) {
             mLocation = getIntent().getExtras().getString("itemLocation");
             itemTitle = getIntent().getExtras().getString("itemTitle");
-            dontParse = getIntent().getExtras().getBoolean("dontParse");
             fromStart = getIntent().getExtras().getBoolean("fromStart");
             itemPosition = getIntent().getExtras().getInt("itemPosition", -1);
         }
@@ -2363,32 +2360,19 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         }
 
         /* Start / resume playback */
-        if(dontParse && itemPosition >= 0) {
-            // Provided externally from AudioService
-            Log.d(TAG, "Continuing playback from AudioService at index " + itemPosition);
-            savedIndexPosition = itemPosition;
-            if(!mLibVLC.isPlaying()) {
-                // AudioService-transitioned playback for item after sleep and resume
-                mMediaListPlayer.playIndex(savedIndexPosition);
-                dontParse = false;
-            }
-            else {
-                stopLoadingAnimation();
-                showOverlay();
-            }
-            updateNavStatus();
-        } else if (savedIndexPosition > -1) {
+        if (savedIndexPosition > -1) {
             AudioServiceController.getInstance().stop(); // Stop the previous playback.
             mMediaListPlayer.playIndex(savedIndexPosition);
-        } else if (mLocation != null && mLocation.length() > 0 && !dontParse) {
+        } else if (mLocation != null && mLocation.length() > 0) {
             AudioServiceController.getInstance().stop(); // Stop the previous playback.
+            mMediaListPlayer.getMediaList().clear();
             mMediaListPlayer.getMediaList().add(new MediaWrapper(mLibVLC, mLocation));
             savedIndexPosition = mMediaListPlayer.getMediaList().size() - 1;
             mMediaListPlayer.playIndex(savedIndexPosition);
         }
         mCanSeek = false;
 
-        if (mLocation != null && mLocation.length() > 0 && !dontParse) {
+        if (mLocation != null && mLocation.length() > 0) {
             // restore last position
             MediaWrapper media = MediaDatabase.getInstance().getMedia(mLocation);
             if(media != null) {
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 6c398ea..0db056b 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -35,6 +35,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.VLCCallbackTask;
 import org.videolan.vlc.audio.AudioServiceController;
+import org.videolan.vlc.gui.video.VideoPlayerActivity;
 
 import android.annotation.TargetApi;
 import android.content.ContentResolver;
@@ -176,21 +177,7 @@ public class Util {
 
 
     public static void openStream(Context context, final String uri){
-        VLCCallbackTask task = new VLCCallbackTask(context){
-            @Override
-            public void run() {
-                AudioServiceController c = AudioServiceController.getInstance();
-
-                      /* Use the audio player by default. If a video track is
-                       * detected, then it will automatically switch to the video
-                       * player. This allows us to support more types of streams
-                       * (for example, RTSP and TS streaming) where ES can be
-                       * dynamically adapted rather than a simple scan.
-                       */
-                c.load(uri, false);
-            }
-        };
-        task.execute();
+        VideoPlayerActivity.start(context, uri);
     }
 
     private static String getMediaString(Context ctx, int id) {



More information about the Android mailing list