diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt index eba772c..1d91ca2 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt @@ -125,6 +125,8 @@ class MPVView(context: Context, attributes: AttributeSet) : BaseMPVView(context, } MPVLib.setOptionString("speed", playerPreferences.defaultSpeed.get().toString()) + // workaround for + MPVLib.setOptionString("vd-lavc-film-grain", "cpu") setupSubtitlesOptions() setupAudioOptions() diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt index 521ec0e..4061a11 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt @@ -317,7 +317,6 @@ class PlayerActivity : AppCompatActivity() { if (it < viewModel.maxVolume) viewModel.changeMPVVolumeTo(100) } } - viewModel.currentBrightness.update { window.attributes.screenBrightness } } private fun setIntentExtras(extras: Bundle?) { diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt index 8d03361..ebd6f36 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt @@ -4,6 +4,7 @@ import android.content.pm.ActivityInfo import android.media.AudioManager import android.net.Uri import android.os.Build +import android.provider.Settings import android.util.DisplayMetrics import android.util.Log import android.widget.Toast @@ -71,7 +72,12 @@ class PlayerViewModel( val playerUpdate = MutableStateFlow(PlayerUpdates.None) val isBrightnessSliderShown = MutableStateFlow(false) val isVolumeSliderShown = MutableStateFlow(false) - val currentBrightness = MutableStateFlow(activity.window.attributes.screenBrightness) + val currentBrightness = MutableStateFlow( + runCatching { + Settings.System.getFloat(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) + .normalize(0f, 255f, 0f, 1f) + }.getOrElse { 0f }, + ) val currentVolume = MutableStateFlow(activity.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)) val currentMPVVolume = MutableStateFlow(MPVLib.getPropertyInt("volume")) var volumeBoostCap: Int = MPVLib.getPropertyInt("volume-max") @@ -431,3 +437,7 @@ data class Track( val name: String, val language: String?, ) + +fun Float.normalize(inMin: Float, inMax: Float, outMin: Float, outMax: Float): Float { + return (this - inMin) * (outMax - outMin) / (inMax - inMin) + outMin +}