[Android] Code cleanup

Nicolas Pomepuy git at videolan.org
Tue Nov 2 13:10:20 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Oct 12 15:23:08 2021 +0200| [e8306f3ee1d4232ea7ea4ae98ca3db49fab1533a] | committer: Nicolas Pomepuy

Code cleanup

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

 .../src/main/java/org/videolan/tools/Settings.kt   |  2 ++
 .../videolan/vlc/gui/video/VideoPlayerActivity.kt  | 34 ++++++++++++----------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index e393b7ff1..bcaa8763a 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -153,6 +153,8 @@ const val AUDIO_DUCKING = "audio_ducking"
 const val AUDIO_DELAY_GLOBAL = "audio_delay_global"
 const val AUDIO_PLAY_PROGRESS_MODE = "audio_play_progress_mode"
 const val AUDIO_STOP_AFTER = "audio_stop_after"
+const val AUDIO_PREFERRED_LANGUAGE = "audio_preferred_language"
+const val SUBTITLE_PREFERRED_LANGUAGE = "subtitle_preferred_language"
 
 const val LAST_LOCK_ORIENTATION = "last_lock_orientation"
 const val INITIAL_PERMISSION_ASKED = "initial_permission_asked"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index afa89e311..a5b6969a5 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1254,14 +1254,15 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                         if (event.esChangedType == IMedia.Track.Type.Audio) {
                             lifecycleScope.launch(Dispatchers.IO) {
                                 val media = medialibrary.findMedia(mw)
-                                var preferredTrack: Int = 0
-                                val contains = settings.getString("audio_preferred_language", null)
-                                val it = PlaybackService.instance?.audioTracks?.iterator()
-                                while (it?.hasNext() === true) {
-                                    val next = it?.next()
-                                    if (next.name.contains(contains.toString(), ignoreCase = true)) {
-                                        preferredTrack = next.id
-                                        break
+                                var preferredTrack = 0
+                                val contains = settings.getString(AUDIO_PREFERRED_LANGUAGE, null)
+                                PlaybackService.instance?.audioTracks?.iterator()?.let {
+                                    while (it.hasNext()) {
+                                        val next = it.next()
+                                        if (next.name.contains(contains.toString(), ignoreCase = true)) {
+                                            preferredTrack = next.id
+                                            break
+                                        }
                                     }
                                 }
                                 val audioTrack = when (val savedTrack = media.getMetaLong(MediaWrapper.META_AUDIOTRACK).toInt()) {
@@ -1274,14 +1275,15 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                         } else if (event.esChangedType == IMedia.Track.Type.Text) {
                             lifecycleScope.launch(Dispatchers.IO) {
                                 val media = medialibrary.findMedia(mw)
-                                var preferredTrack: Int = 0
-                                val contains = settings.getString("subtitle_preferred_language", null)
-                                val it = PlaybackService.instance?.spuTracks?.iterator()
-                                while (it?.hasNext() === true) {
-                                    val next = it?.next()
-                                    if (next.name.contains(contains.toString(), ignoreCase = true)) {
-                                        preferredTrack = next.id
-                                        break
+                                var preferredTrack = 0
+                                val contains = settings.getString(SUBTITLE_PREFERRED_LANGUAGE, null)
+                                PlaybackService.instance?.spuTracks?.iterator()?.let {
+                                    while (it.hasNext()) {
+                                        val next = it.next()
+                                        if (next.name.contains(contains.toString(), ignoreCase = true)) {
+                                            preferredTrack = next.id
+                                            break
+                                        }
                                     }
                                 }
                                 val spuTrack = when (val savedTrack = media.getMetaLong(MediaWrapper.META_SUBTITLE_TRACK).toInt()) {



More information about the Android mailing list