Skip to content

Commit

Permalink
Changing speed sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroBorgesFerreira committed Mar 23, 2023
1 parent c43b94a commit 50853fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public interface RecordsPlayer {

public fun play(sourceUrl: String)

public fun changeSpeed(speed: Float)

public fun currentSpeed(): Float

public fun dispose()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.getstream.chat.android.client.audio

import android.media.MediaPlayer
import android.os.Build
import io.getstream.chat.android.client.scope.UserScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -12,8 +13,8 @@ import kotlinx.coroutines.withContext
internal class StreamMediaPlayer(
private val mediaPlayer: MediaPlayer,
private val userScope: UserScope,
private val progressUpdatePeriod: Long = 50
) : RecordsPlayer{
private val progressUpdatePeriod: Long = 50,
) : RecordsPlayer {

private val onStateListeners: MutableMap<String, (AudioState) -> Unit> = mutableMapOf()
private val onProgressListeners: MutableMap<String, (ProgressData) -> Unit> = mutableMapOf()
Expand All @@ -38,6 +39,15 @@ internal class StreamMediaPlayer(
}
}

override fun changeSpeed(speed: Float) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mediaPlayer.playbackParams = mediaPlayer.playbackParams.setSpeed(speed)
}
}

override fun currentSpeed(): Float =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) mediaPlayer.playbackParams.speed else 1F

override fun dispose() {
stopPooling()
onStateListeners.clear()
Expand Down

0 comments on commit 50853fb

Please sign in to comment.