Skip to content

Commit 3509728

Browse files
authored
Merge pull request #186 from kdroidFilter/fix/playback-speed-range-and-dry
Lower min playback speed to 0.25x and extract constants
2 parents 736135b + 7ec1b24 commit 3509728

7 files changed

Lines changed: 11 additions & 6 deletions

File tree

mediaplayer/src/androidMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.android.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ open class DefaultVideoPlayerState: VideoPlayerState {
215215
override var playbackSpeed: Float
216216
get() = _playbackSpeed
217217
set(value) {
218-
_playbackSpeed = value.coerceIn(0.5f, 2.0f)
218+
_playbackSpeed = value.coerceIn(VideoPlayerState.MIN_PLAYBACK_SPEED, VideoPlayerState.MAX_PLAYBACK_SPEED)
219219
exoPlayer?.let { player ->
220220
player.playbackParameters = PlaybackParameters(_playbackSpeed)
221221
}

mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ interface VideoPlayerState {
5353
var loop: Boolean
5454
var playbackSpeed: Float
5555

56+
companion object {
57+
const val MIN_PLAYBACK_SPEED = 0.25f
58+
const val MAX_PLAYBACK_SPEED = 2.0f
59+
}
60+
5661
/**
5762
* Provides the audio level for the left channel as a percentage.
5863
*/

mediaplayer/src/iosMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.ios.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ open class DefaultVideoPlayerState: VideoPlayerState {
7676
override var playbackSpeed: Float
7777
get() = _playbackSpeed
7878
set(value) {
79-
_playbackSpeed = value.coerceIn(0.5f, 2.0f)
79+
_playbackSpeed = value.coerceIn(VideoPlayerState.MIN_PLAYBACK_SPEED, VideoPlayerState.MAX_PLAYBACK_SPEED)
8080
// Only update player rate if we are playing to avoid auto-play
8181
if (_isPlaying) {
8282
player?.rate = _playbackSpeed

mediaplayer/src/jvmMain/kotlin/io/github/kdroidfilter/composemediaplayer/linux/LinuxVideoPlayerState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class LinuxVideoPlayerState : VideoPlayerState {
141141
override var playbackSpeed: Float
142142
get() = _playbackSpeedState.value
143143
set(value) {
144-
val newValue = value.coerceIn(0.5f, 2.0f)
144+
val newValue = value.coerceIn(VideoPlayerState.MIN_PLAYBACK_SPEED, VideoPlayerState.MAX_PLAYBACK_SPEED)
145145
if (_playbackSpeedState.value != newValue) {
146146
_playbackSpeedState.value = newValue
147147
ioScope.launch { applyPlaybackSpeed() }

mediaplayer/src/jvmMain/kotlin/io/github/kdroidfilter/composemediaplayer/mac/MacVideoPlayerState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class MacVideoPlayerState : VideoPlayerState {
147147
override var playbackSpeed: Float
148148
get() = _playbackSpeedState.value
149149
set(value) {
150-
val newValue = value.coerceIn(0.5f, 2.0f)
150+
val newValue = value.coerceIn(VideoPlayerState.MIN_PLAYBACK_SPEED, VideoPlayerState.MAX_PLAYBACK_SPEED)
151151
if (_playbackSpeedState.value != newValue) {
152152
_playbackSpeedState.value = newValue
153153
// Launch a coroutine to apply the playback speed if the native player is available.

mediaplayer/src/jvmMain/kotlin/io/github/kdroidfilter/composemediaplayer/windows/WindowsVideoPlayerState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class WindowsVideoPlayerState : VideoPlayerState {
169169
override var playbackSpeed: Float
170170
get() = _playbackSpeed
171171
set(value) {
172-
val newSpeed = value.coerceIn(0.5f, 2.0f)
172+
val newSpeed = value.coerceIn(VideoPlayerState.MIN_PLAYBACK_SPEED, VideoPlayerState.MAX_PLAYBACK_SPEED)
173173
if (_playbackSpeed != newSpeed) {
174174
_playbackSpeed = newSpeed
175175
scope.launch {

mediaplayer/src/webMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.web.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ open class DefaultVideoPlayerState: VideoPlayerState {
104104
override var playbackSpeed: Float
105105
get() = _playbackSpeed
106106
set(value) {
107-
val newValue = value.coerceIn(0.5f, 2.0f)
107+
val newValue = value.coerceIn(VideoPlayerState.MIN_PLAYBACK_SPEED, VideoPlayerState.MAX_PLAYBACK_SPEED)
108108
if (_playbackSpeed != newValue) {
109109
_playbackSpeed = newValue
110110
applyPlaybackSpeedWithThrottle(newValue)

0 commit comments

Comments
 (0)