[Android] [PATCH 5/5] VideoPlayer: don't always stop playback on Pause
Thomas Guillem
thomas at gllm.fr
Tue Mar 17 17:41:43 CET 2015
When receiving a telephone call, onPause/onResume is called but the activity is
not finishing. This fix avoid to reload the video when the activity lose the
focus.
---
.../vlc/gui/video/VideoPlayerActivity.java | 33 +++++++++++++++++-----
1 file changed, 26 insertions(+), 7 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 3bc67a1..dc42e17 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -281,6 +281,9 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
private boolean mLostFocus = false;
private boolean mHasAudioFocus = false;
+ /* Flag to indicate if AudioService is bound or binding */
+ private boolean mBound = false;
+
// Tips
private View mOverlayTips;
private static final String PREF_TIPS_SHOWN = "video_player_tips_shown";
@@ -512,8 +515,9 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
protected void onPause() {
super.onPause();
- stopPlayback();
-
+ /* Stop the earliest possible to avoid vout error */
+ if (isFinishing())
+ stopPlayback();
}
@Override
@@ -528,6 +532,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
protected void onStop() {
super.onStop();
+ stopPlayback();
+
// Dismiss the presentation when the activity is not visible.
if (mPresentation != null) {
Log.i(TAG, "Dismissing presentation because the activity is no longer visible.");
@@ -558,11 +564,10 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
mAudioManager = null;
}
- @Override
- protected void onResume() {
- super.onResume();
- mSwitchingView = false;
- mPauseOnLoaded = false;
+ private void bindAudioService() {
+ if (mBound)
+ return;
+ mBound = true;
AudioServiceController.getInstance().bindAudioService(this,
new AudioServiceController.AudioServiceConnectionListener() {
@Override
@@ -572,9 +577,23 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
@Override
public void onConnectionFailed() {
+ mBound = false;
mHandler.sendEmptyMessage(AUDIO_SERVICE_CONNECTION_FAILED);
}
});
+ }
+ private void unbindAudioService() {
+ AudioServiceController.getInstance().unbindAudioService(this);
+ mBound = false;
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mSwitchingView = false;
+ mPauseOnLoaded = false;
+
+ bindAudioService();
if (mIsLocked && mScreenOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR)
setRequestedOrientation(mScreenOrientationLock);
--
2.1.3
More information about the Android
mailing list