<div dir="ltr"><div><div><div>Hello,<br><br></div>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).<br><br></div><div></div></div><div>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.<br><br>But, personally, I definitely doesn't know how to do it.<br><br>Regards<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-01-10 3:30 GMT+01:00 Edward Wang <span dir="ltr"><<a href="mailto:edward.c.wang@compdigitec.com" target="_blank">edward.c.wang@compdigitec.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 .../vlc/gui/video/VideoPlayerActivity.java         | 42 ++++++++++++----------<br>
 1 file changed, 23 insertions(+), 19 deletions(-)<br>
<br>
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java<br>
index 4db04e9..bf22f8d 100644<br>
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java<br>
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java<br>
@@ -262,6 +262,12 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay<br>
     private boolean mDisabledHardwareAcceleration = false;<br>
     private int mPreviousHardwareAccelerationMode;<br>
<br>
+    /**<br>
+     * Flag to indicate whether the media should be paused once loaded<br>
+     * (e.g. lock screen, or to restore the pause state)<br>
+     */<br>
+    private boolean mPauseOnLoaded = false;<br>
+<br>
     // Tips<br>
     private View mOverlayTips;<br>
     private static final String PREF_TIPS_SHOWN = "video_player_tips_shown";<br>
@@ -631,6 +637,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay<br>
     protected void onResume() {<br>
         super.onResume();<br>
         mSwitchingView = false;<br>
+        mPauseOnLoaded = false;<br>
         AudioServiceController.getInstance().bindAudioService(this,<br>
                 new AudioServiceController.AudioServiceConnectionListener() {<br>
                     @Override<br>
@@ -669,23 +676,18 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay<br>
     }<br>
<br>
     private void startPlayback() {<br>
-        loadMedia();<br>
-<br>
         /*<br>
-         * if the activity has been paused by pressing the power button,<br>
+         * If the activity has been paused by pressing the power button, then<br>
          * pressing it again will show the lock screen.<br>
-         * But onResume will also be called, even if vlc-android is still in the background.<br>
-         * To workaround that, pause playback if the lockscreen is displayed<br>
+         * But onResume will also be called, even if vlc-android is still in<br>
+         * the background.<br>
+         * To workaround this, pause playback if the lockscreen is displayed.<br>
          */<br>
-        mHandler.postDelayed(new Runnable() {<br>
-            @Override<br>
-            public void run() {<br>
-                if (mLibVLC != null && mLibVLC.isPlaying()) {<br>
-                    KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);<br>
-                    if (km.inKeyguardRestrictedInputMode())<br>
-                        mLibVLC.pause();<br>
-                }<br>
-            }}, 500);<br>
+        KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);<br>
+        if(km.inKeyguardRestrictedInputMode())<br>
+            mPauseOnLoaded = true;<br>
+<br>
+        loadMedia();<br>
<br>
         // Add any selected subtitle file from the file picker<br>
         if(mSubtitleSelectedFiles.size() > 0) {<br>
@@ -1148,6 +1150,12 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay<br>
                     break;<br>
                 case EventHandler.MediaPlayerPlaying:<br>
                     Log.i(TAG, "MediaPlayerPlaying");<br>
+                    // Handle pause flag<br>
+                    if(activity.mPauseOnLoaded) {<br>
+                        activity.mPauseOnLoaded = false;<br>
+                        activity.mLibVLC.pause();<br>
+                        activity.setOverlayProgress();<br>
+                    }<br>
                     activity.stopLoadingAnimation();<br>
                     activity.showOverlay();<br>
                     /** FIXME: update the track list when it changes during the<br>
@@ -2405,11 +2413,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay<br>
             boolean wasPaused = mSettings.getBoolean(PreferencesActivity.VIDEO_PAUSED, false);<br>
             if(wasPaused) {<br>
                 Log.d(TAG, "Video was previously paused, resuming in paused mode");<br>
-                mHandler.postDelayed(new Runnable() {<br>
-                    @Override<br>
-                    public void run() {<br>
-                        mLibVLC.pause();<br>
-                    }}, 500);<br>
+                mPauseOnLoaded = true;<br>
             }<br>
<br>
             // Get possible subtitles<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.2.1<br>
<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</font></span></blockquote></div><br></div>