[Android] VideoPlayerActivity: Stop the playback while the activity is paused
Ludovic Fauvet
git at videolan.org
Tue Sep 25 11:28:45 CEST 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Tue Sep 25 01:39:58 2012 +0200| [c0827d9e49cd7b11a19ef48a0de3b0fda6b47c7f] | committer: Ludovic Fauvet
VideoPlayerActivity: Stop the playback while the activity is paused
Instead of pausing the playback in onPause we stop it completely to
prevent the output thread from running while the application is in the
background. The playback is then restarted at the same position in the
onResume method.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c0827d9e49cd7b11a19ef48a0de3b0fda6b47c7f
---
.../vlc/gui/video/VideoPlayerActivity.java | 30 ++++++++++++++++++--
1 file changed, 28 insertions(+), 2 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 0afa4f3..62aa1c7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -145,6 +145,9 @@ public class VideoPlayerActivity extends Activity {
private boolean mSwitchingView;
private boolean mEndReached;
+ // Playlist
+ private int savedIndexPosition = -1;
+
// size of the video
private int mVideoHeight;
private int mVideoWidth;
@@ -319,9 +322,24 @@ public class VideoPlayerActivity extends Activity {
time = 0;
else
time -= 5000; // go back 5 seconds, to compensate loading time
- if (mLibVLC.isPlaying()) {
+
+ /*
+ * Pausing here generates errors because the vout is constantly
+ * trying to refresh itself every 80ms while the surface is not
+ * accessible anymore.
+ * To workaround that, we keep the last known position in the playlist
+ * in savedIndexPosition to be able to restore it during onResume().
+ */
+ if (savedIndexPosition >= 0)
+ mLibVLC.stop();
+ else {
+ /* FIXME when the playback is started externally from AudioService
+ * we don't have a savedIndexPosition. Use pause as a fallback until
+ * we find a solution.
+ */
mLibVLC.pause();
}
+
mSurface.setKeepScreenOn(false);
// Save position
@@ -362,6 +380,14 @@ public class VideoPlayerActivity extends Activity {
@Override
protected void onResume() {
AudioServiceController.getInstance().bindAudioService(this);
+
+ if (savedIndexPosition >= 0) {
+ mLibVLC.playIndex(savedIndexPosition);
+ Media media = DatabaseManager.getInstance(this).getMedia(this, mLocation);
+ if (media != null && media.getTime() > 0)
+ mLibVLC.setTime(media.getTime());
+ }
+
super.onResume();
}
@@ -1185,7 +1211,7 @@ public class VideoPlayerActivity extends Activity {
mSurface.setKeepScreenOn(true);
if (mLocation != null && mLocation.length() > 0 && !dontParse) {
- mLibVLC.readMedia(mLocation, false);
+ savedIndexPosition = mLibVLC.readMedia(mLocation, false);
// restore last position
Media media = DatabaseManager.getInstance(this).getMedia(this, mLocation);
More information about the Android
mailing list