[Android] seek methods for playbackService

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


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun  9 16:11:24 2016 +0200| [0d3b889a018908a000e46fdc76dc3dbfd320f413] | committer: Geoffrey Métais

seek methods for playbackService

Handle setPosition, then setTime if length is not available.

> https://code.videolan.org/videolan/vlc-android/commit/0d3b889a018908a000e46fdc76dc3dbfd320f413
---

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

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index b452f70..e3b7b74 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1110,7 +1110,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
 
         @Override
         public void onSeekTo(long pos) {
-            setTime(pos);
+            seek(pos);
         }
 
         @Override
@@ -1342,7 +1342,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         // load playlist
         loadLocations(mediaPathList, position);
         if (time > 0)
-            setTime(time);
+            seek(time);
         if(!audio) {
             boolean paused = mSettings.getBoolean(PreferencesActivity.VIDEO_PAUSED, !isPlaying());
             float rate = mSettings.getFloat(PreferencesActivity.VIDEO_SPEED, getRate());
@@ -1741,7 +1741,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
             mMediaPlayer.setEventListener(mMediaPlayerListener);
             mMediaPlayer.play();
             if(mSavedTime != 0l)
-                mMediaPlayer.setTime(mSavedTime);
+                seek(mSavedTime);
             mSavedTime = 0l;
 
             determinePrevAndNextIndices();
@@ -1995,6 +1995,19 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     }
 
     @MainThread
+    public void seek(long position) {
+        seek(position, getLength());
+    }
+
+    @MainThread
+    public void seek(long position, long length) {
+        if (length > 0)
+            setPosition(position/length);
+        else
+            setTime(position);
+    }
+
+    @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 e7cd68a..929d5ff 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2507,10 +2507,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     private void seek(long position, float length) {
         mForcedTime = position;
         mLastTime = mService.getTime();
-        if (length <= 0f)
-            mService.setTime(position);
-        else
-            mService.setPosition(position / length);
+        mService.seek(position, length);
     }
 
     private void seekDelta(int delta) {



More information about the Android mailing list