[Android] Medialibrary: pause parsing on video playback only

Geoffrey Métais git at videolan.org
Fri Jul 5 11:06:00 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul  5 11:05:21 2019 +0200| [6698cfd2a430625bc7c30287d441e4bac2fefb19] | committer: Geoffrey Métais

Medialibrary: pause parsing on video playback only

> https://code.videolan.org/videolan/vlc-android/commit/6698cfd2a430625bc7c30287d441e4bac2fefb19
---

 vlc-android/src/org/videolan/vlc/PlaybackService.kt               | 1 -
 vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 4 +++-
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt         | 7 +------
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index decf2b986..e1ae26055 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -605,7 +605,6 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
         removePopup()
         if (wakeLock.isHeld) wakeLock.release()
         audioFocusHelper.changeAudioFocus(false)
-        medialibrary.resumeBackgroundOperations()
         // We must publish state before resetting mCurrentIndex
         publishState()
         executeUpdate()
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 2478bcab5..f1f366370 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -83,9 +83,9 @@ import org.videolan.libvlc.RendererItem
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.libvlc.util.DisplayManager
 import org.videolan.libvlc.util.VLCVideoLayout
-import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.Tools
+import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
 import org.videolan.tools.*
 import org.videolan.vlc.*
@@ -704,6 +704,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
 
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
     override fun onStart() {
+        medialibrary.pauseBackgroundOperations()
         super.onStart()
         PlaybackService.start(this)
         PlaybackService.service.observe(this, this)
@@ -749,6 +750,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
         removeDownloadedSubtitlesObserver()
         previousMediaPath = null
         addedExternalSubs.clear()
+        medialibrary.resumeBackgroundOperations()
     }
 
     private fun saveBrightness() {
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 93e1d2ec7..0ab35ff1a 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -16,8 +16,8 @@ import org.videolan.libvlc.Media
 import org.videolan.libvlc.MediaPlayer
 import org.videolan.libvlc.RendererItem
 import org.videolan.libvlc.util.AndroidUtil
-import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.medialibrary.MLServiceLocator
+import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.PlaybackService
@@ -123,7 +123,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 Log.w(TAG, "Warning: empty media list, nothing to play !")
                 return at launch
             }
-            medialibrary.pauseBackgroundOperations()
             currentIndex = if (isValidPosition(position)) position else 0
 
             // Add handler after loading the list
@@ -226,7 +225,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         mediaList.clear()
         showAudioPlayer.value = false
         service.onPlaybackStopped(systemExit)
-        medialibrary.resumeBackgroundOperations()
         //Close video player if started
         LocalBroadcastManager.getInstance(ctx).sendBroadcast(Intent(EXIT_PLAYER))
     }
@@ -272,7 +270,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     suspend fun playIndex(index: Int, flags: Int = 0) {
         if (mediaList.size() == 0) {
             Log.w(TAG, "Warning: empty media list, nothing to play !")
-            medialibrary.resumeBackgroundOperations()
             return
         }
         currentIndex = if (isValidPosition(index)) {
@@ -743,7 +740,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         override suspend fun onEvent(event: MediaPlayer.Event) {
             when (event.type) {
                 MediaPlayer.Event.Playing -> {
-                    medialibrary.pauseBackgroundOperations()
                     val mw = withContext(Dispatchers.IO) {
                         getCurrentMedia()?.let {
                             medialibrary.findMedia(it).apply {
@@ -761,7 +757,6 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                         savePlaycount(mw)
                     }
                 }
-                MediaPlayer.Event.Paused -> medialibrary.resumeBackgroundOperations()
                 MediaPlayer.Event.EndReached -> {
                     clearABRepeat()
                     if (currentIndex != nextIndex) {



More information about the Android mailing list