-1

I am implementing a audio player using mediaplayer. In jetpack compose, there is Slider which only accepts float value but duration and currentPostion of MediaPlayer is Int, even though I convert to float it will not get 100% of progress. Also I want to implement a seekbar in slider whenever I move the seekbar it move the current position of MediaPlayer too.

bovietvidai
  • 105
  • 5
  • https://stackoverflow.com/questions/70032046/hook-compose-slider-to-mediaplayer does this help?. its float i guess – Raghunandan Nov 25 '22 at 05:10

1 Answers1

1

Not sure if I understand you correctly, but if you want to get the position of the running video/media from moving the Slider, consider this, assuming you are computing and setting the media position as seconds, just multiply the slider value to your duration(seconds).

@Composable
fun SliderSample(mediaDuration: Int) {

    var sliderValue by remember {
        mutableStateOf(0f)
    }

    Slider(
        value = sliderValue,
        onValueChange = {
            sliderValue = it
        }
    )

    val seekDuration = sliderValue * mediaDuration

    // replace this log statement with the media that accepts an integer seconds
    Log.e("SliderValue", "${seekDuration.toInt()}")
}
setContent {
     SliderSample(180) // 3 minutes
}
z.g.y
  • 5,512
  • 4
  • 10
  • 36