[Android] Video player: prevent IO from main thread

Geoffrey Métais git at videolan.org
Fri Dec 20 16:43:54 CET 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 20 16:35:29 2019 +0100| [ca0d82ffcc0b2d2c0b635b256dc28167d9425845] | committer: Geoffrey Métais

Video player: prevent IO from main thread

(cherry picked from commit 282030aef5c238a9260bcf77ead32c99675a81ca)

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

 vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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 cba2114c8..6787c5b58 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -98,6 +98,7 @@ import org.videolan.vlc.repository.ExternalSubRepository
 import org.videolan.vlc.repository.SlaveRepository
 import org.videolan.vlc.util.*
 import org.videolan.vlc.viewmodels.PlaylistModel
+import java.lang.Runnable
 
 @Suppress("DEPRECATION")
 @ObsoleteCoroutinesApi
@@ -1486,10 +1487,11 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
                 }
                 MediaPlayer.Event.ESAdded -> {
                     if (menuIdx == -1) {
-                        val media = medialibrary.findMedia(service.currentMediaWrapper) ?: return
+                        val mw = service.currentMediaWrapper ?: return
                         if (event.esChangedType == Media.Track.Type.Audio) {
                             setESTrackLists()
                             runIO(Runnable {
+                                val media = medialibrary.findMedia(mw)
                                 val audioTrack = media.getMetaLong(AbstractMediaWrapper.META_AUDIOTRACK).toInt()
                                 if (audioTrack != 0 || currentAudioTrack != -2)
                                     service.setAudioTrack(if (media.id == 0L) currentAudioTrack else audioTrack)
@@ -1497,6 +1499,7 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
                         } else if (event.esChangedType == Media.Track.Type.Text) {
                             setESTrackLists()
                             runIO(Runnable {
+                                val media = medialibrary.findMedia(mw)
                                 val spuTrack = media.getMetaLong(AbstractMediaWrapper.META_SUBTITLE_TRACK).toInt()
                                 if (addNextTrack) {
                                     val tracks = service.spuTracks



More information about the Android mailing list