[Android] Fix "Play from start"

Geoffrey Métais git at videolan.org
Thu Oct 25 10:25:45 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 25 10:25:25 2018 +0200| [2223df5f32065ebcfdac6e6c4f0684237c8e9dd4] | committer: Geoffrey Métais

Fix "Play from start"

> https://code.videolan.org/videolan/vlc-android/commit/2223df5f32065ebcfdac6e6c4f0684237c8e9dd4
---

 .../org/videolan/medialibrary/media/MediaWrapper.java   |  1 +
 .../org/videolan/vlc/gui/video/VideoGridFragment.java   |  3 ++-
 .../src/org/videolan/vlc/media/PlaylistManager.kt       | 17 ++++++++++++-----
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
index e17196682..97f5b8c0e 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaWrapper.java
@@ -55,6 +55,7 @@ public class MediaWrapper extends MediaLibraryItem implements Parcelable {
     public final static int MEDIA_PAUSED = 0x4;
     public final static int MEDIA_FORCE_AUDIO = 0x8;
     public final static int MEDIA_BENCHMARK = 0x10;
+    public final static int MEDIA_FROM_START = 0x20;
 
     //MetaData flags
     public final static int META_RATING = 1;
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 2d74b03a9..5bff93c5e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -192,7 +192,8 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
 
     protected void playVideo(MediaWrapper media, boolean fromStart) {
         media.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
-        VideoPlayerActivity.start(getActivity(), media.getUri(), fromStart);
+        if (fromStart) media.addFlags(MediaWrapper.MEDIA_FROM_START);
+        MediaUtils.INSTANCE.openMedia(requireContext(), media);
     }
 
     protected void playAudio(MediaWrapper media) {
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 3f2a9acfa..25fcc5db5 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -592,11 +592,18 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     fun getMedia(position: Int) = mediaList.getMedia(position)
 
     private suspend fun getStartTime(mw: MediaWrapper) : Long {
-        val start = if (savedTime <= 0L) when {
-            mw.time >= 0L -> mw.time
-            mw.type == MediaWrapper.TYPE_VIDEO || mw.isPodcast -> withContext(IO) { medialibrary.findMedia(mw).getMetaLong(MediaWrapper.META_PROGRESS) }
-            else -> 0L
-        } else savedTime
+        val start = when {
+            mw.hasFlag(MediaWrapper.MEDIA_FROM_START) -> {
+                mw.removeFlags(MediaWrapper.MEDIA_FROM_START)
+                0L
+            }
+            savedTime <= 0L -> when {
+                mw.time >= 0L -> mw.time
+                mw.type == MediaWrapper.TYPE_VIDEO || mw.isPodcast -> withContext(Dispatchers.IO) { medialibrary.findMedia(mw).getMetaLong(MediaWrapper.META_PROGRESS) }
+                else -> 0L
+            }
+            else -> savedTime
+        }
         savedTime = 0L
         return start/1000L
     }



More information about the Android mailing list