[Android] [PATCH] Use callback for pauses instead of postDelayed

Alexandre Perraud 4leyx4ndre at gmail.com
Mon Jan 12 18:11:44 CET 2015


Hello,

You take the same path I took few months ago : it's still not a good idea,
you have audio glitch when VLC get the focus (if you switch app for
example).

We discussed about that, here, and we came to the conclusion that the good
way to do that should be to have a function, in the core, which directly
launch a video on pause.

But, personally, I definitely doesn't know how to do it.

Regards


2015-01-10 3:30 GMT+01:00 Edward Wang <edward.c.wang at compdigitec.com>:

> ---
>  .../vlc/gui/video/VideoPlayerActivity.java         | 42
> ++++++++++++----------
>  1 file changed, 23 insertions(+), 19 deletions(-)
>
> 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 4db04e9..bf22f8d 100644
> --- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
> +++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
> @@ -262,6 +262,12 @@ public class VideoPlayerActivity extends
> ActionBarActivity implements IVideoPlay
>      private boolean mDisabledHardwareAcceleration = false;
>      private int mPreviousHardwareAccelerationMode;
>
> +    /**
> +     * Flag to indicate whether the media should be paused once loaded
> +     * (e.g. lock screen, or to restore the pause state)
> +     */
> +    private boolean mPauseOnLoaded = false;
> +
>      // Tips
>      private View mOverlayTips;
>      private static final String PREF_TIPS_SHOWN =
> "video_player_tips_shown";
> @@ -631,6 +637,7 @@ public class VideoPlayerActivity extends
> ActionBarActivity implements IVideoPlay
>      protected void onResume() {
>          super.onResume();
>          mSwitchingView = false;
> +        mPauseOnLoaded = false;
>          AudioServiceController.getInstance().bindAudioService(this,
>                  new
> AudioServiceController.AudioServiceConnectionListener() {
>                      @Override
> @@ -669,23 +676,18 @@ public class VideoPlayerActivity extends
> ActionBarActivity implements IVideoPlay
>      }
>
>      private void startPlayback() {
> -        loadMedia();
> -
>          /*
> -         * if the activity has been paused by pressing the power button,
> +         * If the activity has been paused by pressing the power button,
> then
>           * pressing it again will show the lock screen.
> -         * But onResume will also be called, even if vlc-android is still
> in the background.
> -         * To workaround that, pause playback if the lockscreen is
> displayed
> +         * But onResume will also be called, even if vlc-android is still
> in
> +         * the background.
> +         * To workaround this, pause playback if the lockscreen is
> displayed.
>           */
> -        mHandler.postDelayed(new Runnable() {
> -            @Override
> -            public void run() {
> -                if (mLibVLC != null && mLibVLC.isPlaying()) {
> -                    KeyguardManager km =
> (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
> -                    if (km.inKeyguardRestrictedInputMode())
> -                        mLibVLC.pause();
> -                }
> -            }}, 500);
> +        KeyguardManager km =
> (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
> +        if(km.inKeyguardRestrictedInputMode())
> +            mPauseOnLoaded = true;
> +
> +        loadMedia();
>
>          // Add any selected subtitle file from the file picker
>          if(mSubtitleSelectedFiles.size() > 0) {
> @@ -1148,6 +1150,12 @@ public class VideoPlayerActivity extends
> ActionBarActivity implements IVideoPlay
>                      break;
>                  case EventHandler.MediaPlayerPlaying:
>                      Log.i(TAG, "MediaPlayerPlaying");
> +                    // Handle pause flag
> +                    if(activity.mPauseOnLoaded) {
> +                        activity.mPauseOnLoaded = false;
> +                        activity.mLibVLC.pause();
> +                        activity.setOverlayProgress();
> +                    }
>                      activity.stopLoadingAnimation();
>                      activity.showOverlay();
>                      /** FIXME: update the track list when it changes
> during the
> @@ -2405,11 +2413,7 @@ public class VideoPlayerActivity extends
> ActionBarActivity implements IVideoPlay
>              boolean wasPaused =
> mSettings.getBoolean(PreferencesActivity.VIDEO_PAUSED, false);
>              if(wasPaused) {
>                  Log.d(TAG, "Video was previously paused, resuming in
> paused mode");
> -                mHandler.postDelayed(new Runnable() {
> -                    @Override
> -                    public void run() {
> -                        mLibVLC.pause();
> -                    }}, 500);
> +                mPauseOnLoaded = true;
>              }
>
>              // Get possible subtitles
> --
> 2.2.1
>
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20150112/6a496913/attachment.html>


More information about the Android mailing list