[Android] Prevent infinite loop in media playback

Geoffrey Métais git at videolan.org
Thu Mar 1 12:40:09 CET 2018


vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar  1 11:07:25 2018 +0100| [9fb2c7d8e02abe6c3ffbe2cc6138ecd1c7655977] | committer: Geoffrey Métais

Prevent infinite loop in media playback

If no audio track is detected and repeat was activated, we could loop on the same media trying to
skipping it

(cherry picked from commit b3dbb29afa49b818af230a4496c6842799d339cc)

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt      | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 1738b962d..ef53f1afc 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -241,11 +241,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         player.switchToVideo = false
         if (TextUtils.equals(mw.uri.scheme, "content")) MediaUtils.retrieveMediaTitle(mw)
 
-        if (mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) && player.getAudioTracksCount() == 0) {
-            next()
-        } else if (mw.type != MediaWrapper.TYPE_VIDEO || isVideoPlaying || player.hasRenderer
-                || mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO)) {
-            launch(UI, CoroutineStart.UNDISPATCHED) {
+        launch(UI, CoroutineStart.UNDISPATCHED) {
+            if (mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) && player.getAudioTracksCount() == 0) {
+                determinePrevAndNextIndices(true)
+                if (currentIndex != nextIndex) next()
+                else stop(false)
+            } else if (mw.type != MediaWrapper.TYPE_VIDEO || isVideoPlaying || player.hasRenderer
+                    || mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO)) {
                 val media = Media(VLCInstance.get(), FileUtils.getUri(mw.uri))
                 VLCOptions.setMediaOptions(media, ctx, flags or mw.flags)
                 /* keeping only video during benchmark */
@@ -284,10 +286,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 }
                 saveCurrentMedia()
                 newMedia = true
+            } else { //Start VideoPlayer for first video, it will trigger playIndex when ready.
+                player.stop()
+                VideoPlayerActivity.startOpened(ctx, mw.uri, currentIndex)
             }
-        } else { //Start VideoPlayer for first video, it will trigger playIndex when ready.
-            player.stop()
-            VideoPlayerActivity.startOpened(ctx, mw.uri, currentIndex)
         }
     }
 



More information about the Android mailing list