[Android] Let PlaybackService to handle seek on media load

Geoffrey Métais git at videolan.org
Thu Jun 9 17:13:58 CEST 2016


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

Let PlaybackService to handle seek on media load

(cherry picked from commit 267671dcf82a283849e188878427d62a42d44977)

> https://code.videolan.org/videolan/vlc-android/commit/9fa688441c0a2b6237fbb243cecabaacc07a1b70
---

 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 bf69be6..1166335 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 e5be8a1..fa07d54 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