[Android] Fix IllegalStateException in AudioPlayer

Nicolas Pomepuy git at videolan.org
Mon Jan 27 16:52:17 CET 2020


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jan 27 16:31:25 2020 +0100| [5d47b5007f052a64e4b5d59dcc4a66b616062db4] | committer: Geoffrey Métais

Fix IllegalStateException in AudioPlayer

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

 vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index eb3ae3fee..db50fdfbb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -227,8 +227,9 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, CoroutineS
 
     private var wasPlaying = true
     private fun updatePlayPause() {
+        val ctx = context ?: return
         val playing = playlistModel.playing
-        val text = getString(if (playing) R.string.pause else R.string.play)
+        val text = ctx.getString(if (playing) R.string.pause else R.string.play)
 
         val drawable = if (playing) playToPause else pauseToPlay
         val drawableSmall = if (playing) playToPauseSmall else pauseToPlaySmall
@@ -247,30 +248,32 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, CoroutineS
 
     private var wasShuffling = false
     private fun updateShuffleMode() {
+        val ctx = context ?: return
         binding.shuffle.visibility = if (playlistModel.canShuffle) View.VISIBLE else View.INVISIBLE
         val shuffling = playlistModel.shuffling
         if (wasShuffling == shuffling) return
         binding.shuffle.setImageResource(if (shuffling) R.drawable.ic_shuffle_on else R.drawable.ic_shuffle)
-        binding.shuffle.contentDescription = resources.getString(if (shuffling) R.string.shuffle_on else R.string.shuffle)
+        binding.shuffle.contentDescription = ctx.getString(if (shuffling) R.string.shuffle_on else R.string.shuffle)
         wasShuffling = shuffling
     }
 
     private var previousRepeatType = -1
     private fun updateRepeatMode() {
+        val ctx = context ?: return
         val repeatType = playlistModel.repeatType
         if (previousRepeatType == repeatType) return
         when (repeatType) {
             REPEAT_ONE -> {
                 binding.repeat.setImageResource(R.drawable.ic_repeat_one)
-                binding.repeat.contentDescription = resources.getString(R.string.repeat_single)
+                binding.repeat.contentDescription = ctx.getString(R.string.repeat_single)
             }
             REPEAT_ALL -> {
                 binding.repeat.setImageResource(R.drawable.ic_repeat_all)
-                binding.repeat.contentDescription = resources.getString(R.string.repeat_all)
+                binding.repeat.contentDescription = ctx.getString(R.string.repeat_all)
             }
             else -> {
                 binding.repeat.setImageResource(R.drawable.ic_repeat)
-                binding.repeat.contentDescription = resources.getString(R.string.repeat)
+                binding.repeat.contentDescription = ctx.getString(R.string.repeat)
             }
         }
         previousRepeatType = repeatType



More information about the Android mailing list