[Android] Let PlaybackService to handle seek on media load

Geoffrey Métais git at videolan.org
Thu Jun 9 16:44:01 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun  9 16:43:18 2016 +0200| [267671dcf82a283849e188878427d62a42d44977] | committer: Geoffrey Métais

Let PlaybackService to handle seek on media load

> https://code.videolan.org/videolan/vlc-android/commit/267671dcf82a283849e188878427d62a42d44977
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java   | 11 ++++++++---
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java | 17 ++++++-----------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index e3b7b74..9d4d106 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -2000,14 +2000,19 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     }
 
     @MainThread
-    public void seek(long position, long length) {
-        if (length > 0)
-            setPosition(position/length);
+    public void seek(long position, double length) {
+        if (length > 0.0D)
+            setPosition((float) (position/length));
         else
             setTime(position);
     }
 
     @MainThread
+    public void saveTimeToSeek(long time) {
+        mSavedTime = time;
+    }
+
+    @MainThread
     public void setPosition(float pos) {
         if (mSeekable)
             mMediaPlayer.setPosition(pos);
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 929d5ff..9d828c1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2504,7 +2504,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         seek(position, mService.getLength());
     }
 
-    private void seek(long position, float length) {
+    private void seek(long position, long length) {
         mForcedTime = position;
         mLastTime = mService.getTime();
         mService.seek(position, length);
@@ -2977,25 +2977,20 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             media.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
             media.addFlags(MediaWrapper.MEDIA_VIDEO);
 
-            boolean seek = true;
+            if (savedTime <= 0 && media != null && media.getTime() > 0l)
+                savedTime = media.getTime();
+            if (savedTime > 0L && !mService.isPlaying())
+                mService.saveTimeToSeek(savedTime);
+
             // Handle playback
             if (!hasMedia)
                 mService.load(media);
             else if (!mService.isPlaying())
                 mService.playIndex(positionInPlaylist);
             else {
-                seek = false;
                 onPlaying();
             }
 
-            if (seek) {
-                // Set time
-                if (savedTime <= 0 && media != null && media.getTime() > 0l)
-                    savedTime = media.getTime();
-                if (savedTime > 0)
-                    seek(savedTime);
-            }
-
             // Get possible subtitles
             getSubtitles();
 



More information about the Android mailing list