Skip to content

Commit

Permalink
fix: use system brightness as default
Browse files Browse the repository at this point in the history
closes #85
also apply vd-lavc-film-grain=cpu by default (mpv-android/mpv-android@a36a9a4)
  • Loading branch information
abdallahmehiz committed Sep 23, 2024
1 parent 49f1cc5 commit ab5e139
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/MPVView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class MPVView(context: Context, attributes: AttributeSet) : BaseMPVView(context,
}

MPVLib.setOptionString("speed", playerPreferences.defaultSpeed.get().toString())
// workaround for <https://github.com/mpv-player/mpv/issues/14651>
MPVLib.setOptionString("vd-lavc-film-grain", "cpu")

setupSubtitlesOptions()
setupAudioOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

0 comments on commit ab5e139

Please sign in to comment.