[Android] [PATCH 1/3] Handle videos playlists
Edward Wang
edward.c.wang at compdigitec.com
Wed Nov 25 09:35:25 CET 2015
Video playlists? (for commit title)
On Tue, Nov 24, 2015 at 8:25 AM, Geoffrey Métais
<geoffrey.metais at gmail.com> wrote:
> ---
> .../src/org/videolan/vlc/PlaybackService.java | 13 +++++----
> .../org/videolan/vlc/gui/audio/AudioPlayer.java | 11 --------
> .../vlc/gui/video/VideoPlayerActivity.java | 31 ++++++++++++++--------
> 3 files changed, 28 insertions(+), 27 deletions(-)
>
> diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
> index e9d4cf0..cfb5850 100644
> --- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
> +++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
> @@ -576,9 +576,12 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
> }
>
> changeAudioFocus(true);
> - showNotification();
> if (!mWakeLock.isHeld())
> mWakeLock.acquire();
> + if (switchToVideo())
> + hideNotification();
> + else
> + showNotification();
> break;
> case MediaPlayer.Event.Paused:
> Log.i(TAG, "MediaPlayer.Event.Paused");
> @@ -722,8 +725,8 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
> public boolean switchToVideo() {
> if (!canSwitchToVideo())
> return false;
> - if (!mMediaPlayer.getVLCVout().areViewsAttached())
> - VideoPlayerActivity.startOpened(VLCApplication.getAppContext(), mCurrentIndex);
> + VideoPlayerActivity.startOpened(VLCApplication.getAppContext(),
> + getCurrentMediaWrapper().getUri(), mCurrentIndex);
> return true;
> }
>
> @@ -1142,7 +1145,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
> }
>
> playIndex(mCurrentIndex, 0);
> - onMediaChanged();
> + saveCurrentMedia();
> }
>
> @MainThread
> @@ -1161,7 +1164,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
> setPosition(0f);
>
> playIndex(mCurrentIndex, 0);
> - onMediaChanged();
> + saveCurrentMedia();
> }
>
> @MainThread
> diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
> index 3ebdad1..6d7829a 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
> @@ -95,7 +95,6 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
>
> private boolean mShowRemainingTime = false;
> private boolean mPreviewingSeek = false;
> - private boolean mSwitchedToVideo = false;
>
> private PlaylistAdapter mPlaylistAdapter;
>
> @@ -176,7 +175,6 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
> public void onClick(View v) {
> if (mService != null) {
> mService.switchToVideo();
> - mSwitchedToVideo = true;
> }
> }
> });
> @@ -301,7 +299,6 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
> if (mSettings.getBoolean(PreferencesActivity.VIDEO_RESTORE, false)){
> Util.commitPreferences(mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false));
> mService.switchToVideo();
> - mSwitchedToVideo = true;
> return;
> } else
> show();
> @@ -383,14 +380,6 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
> public void onMediaPlayerEvent(MediaPlayer.Event event) {
> switch (event.type) {
> case MediaPlayer.Event.Opening:
> - mSwitchedToVideo = false;
> - break;
> - case MediaPlayer.Event.ESAdded:
> - final boolean forceAudio = (mService.getCurrentMediaWrapper().getFlags() & MediaWrapper.MEDIA_FORCE_AUDIO) != 0;
> - if (!forceAudio && !mSwitchedToVideo && event.getEsChangedType() == Media.Track.Type.Video) {
> - mService.switchToVideo();
> - mSwitchedToVideo = true;
> - }
> break;
> case MediaPlayer.Event.Stopped:
> hide();
> 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 c81357b..cd7e4e0 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
> @@ -240,9 +240,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> private boolean mHardwareAccelerationError;
> private boolean mEndReached;
> private boolean mHasSubItems = false;
> + private boolean mForceStop = false;
>
> // Playlist
> private int savedIndexPosition = -1;
> + private boolean mHasNext = false;
>
> // size of the video
> private int mVideoHeight;
> @@ -536,7 +538,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> protected void onNewIntent(Intent intent) {
> setIntent(intent);
> if (mPlaybackStarted) {
> - Uri uri = intent.hasExtra(PLAY_EXTRA_ITEM_LOCATION) ? (Uri) intent.getExtras().getParcelable(PLAY_EXTRA_ITEM_LOCATION) : intent.getData();
> + Uri uri = intent.hasExtra(PLAY_EXTRA_ITEM_LOCATION) ?
> + (Uri) intent.getExtras().getParcelable(PLAY_EXTRA_ITEM_LOCATION) : intent.getData();
> if (uri == null || uri.equals(mUri))
> return;
> stopPlayback();
> @@ -820,7 +823,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> time = 0;
> else
> time -= 2000; // go back 2 seconds, to compensate loading time
> - mService.stop();
> + if (mForceStop || !mHasNext)
> + mService.stop();
>
> SharedPreferences.Editor editor = mSettings.edit();
> // Save position
> @@ -885,8 +889,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> public static void start(Context context, Uri uri, String title) {
> start(context, uri, title, false, -1);
> }
> - public static void startOpened(Context context, int openedPosition) {
> - start(context, null, null, false, openedPosition);
> + public static void startOpened(Context context, Uri uri, int openedPosition) {
> + start(context, uri, null, false, openedPosition);
> }
>
> private static void start(Context context, Uri uri, String title, boolean fromStart, int openedPosition) {
> @@ -895,10 +899,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> intent.putExtra(PLAY_EXTRA_ITEM_LOCATION, uri);
> intent.putExtra(PLAY_EXTRA_ITEM_TITLE, title);
> intent.putExtra(PLAY_EXTRA_FROM_START, fromStart);
> - intent.putExtra(PLAY_EXTRA_OPENED_POSITION, openedPosition);
>
> - if (openedPosition != -1)
> - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
> + if (openedPosition != -1) {
> + intent.putExtra(PLAY_EXTRA_OPENED_POSITION, openedPosition);
> + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> + }
>
> context.startActivity(intent);
> }
> @@ -1011,8 +1016,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> endDelaySetting();
> } else if (BuildConfig.tv && mShowing && !mIsLocked) {
> hideOverlay(true);
> - } else
> + } else {
> + mForceStop = true;
> exitOK();
> + }
> }
>
> @Override
> @@ -1031,13 +1038,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> showOverlayTimeout(OVERLAY_TIMEOUT);
> switch (keyCode) {
> case KeyEvent.KEYCODE_F:
> - case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
> case KeyEvent.KEYCODE_MEDIA_NEXT:
> + case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
> seekDelta(10000);
> return true;
> case KeyEvent.KEYCODE_R:
> + case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
> case KeyEvent.KEYCODE_MEDIA_REWIND:
> - case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
> seekDelta(-10000);
> return true;
> case KeyEvent.KEYCODE_BUTTON_R1:
> @@ -1511,7 +1518,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> });
> } else {
> /* Exit player when reaching the end */
> - mEndReached = true;
> + mEndReached = !mService.hasNext();
> exitOK();
> }
> }
> @@ -2795,6 +2802,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
> onPlaying();
> }
>
> + mHasNext = mService.hasNext();
> +
> // Get possible subtitles
> String subtitleList_serialized = mSettings.getString(PreferencesActivity.VIDEO_SUBTITLE_FILES, null);
> ArrayList<String> prefsList = new ArrayList<String>();
> --
> 2.5.0
>
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android
More information about the Android
mailing list