[Android] Restore volume when switching apps and volume > 100

Nicolas Pomepuy git at videolan.org
Tue Jun 22 04:13:46 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 17 07:29:23 2021 +0200| [99daa043882f3e237a05dd1afc613aeb8687137d] | committer: Nicolas Pomepuy

Restore volume when switching apps and volume > 100

Fixes #740

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

 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt            | 2 ++
 .../vlc-android/src/org/videolan/vlc/media/PlayerController.kt       | 5 +++++
 2 files changed, 7 insertions(+)

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 a19cd0051..a8cfa96bf 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
@@ -1437,6 +1437,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 service.setVolume(vol.toFloat().roundToInt())
             }
             overlayDelegate.showVolumeBar(vol, fromTouch)
+            volSave = service.volume
         }
     }
 
@@ -2035,6 +2036,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
             handler.post {
                 // delay mediaplayer loading, prevent ANR
                 if (service.volume > 100 && !isAudioBoostEnabled) service.setVolume(100)
+                if (volSave > 100 && service.volume != volSave) service.setVolume(volSave)
             }
             service.addCallback(this)
         } else if (this.service != null) {
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index ebe59fa08..ed0af17e7 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -3,6 +3,7 @@ package org.videolan.vlc.media
 import android.content.Context
 import android.net.Uri
 import android.support.v4.media.session.PlaybackStateCompat
+import android.util.Log
 import android.widget.Toast
 import androidx.annotation.MainThread
 import androidx.core.net.toUri
@@ -99,7 +100,11 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
     @MainThread
     fun restart() {
         val mp = mediaplayer
+        val volume = mp.volume
         mediaplayer = newMediaPlayer()
+        if (volume != 100) {
+            mediaplayer.volume = volume
+        }
         release(mp)
     }
 



More information about the Android mailing list