'Change speed of audio file in kotlin

I am making a metronome app in Android Studio, using Kotlin, and need to be able to change the speed of the audio file playing.

Min SDK: 23 Target SDK: 32

This is what I've currently got but changing the playBackSpeed variable doesn't change the playback speed.

val play = findViewById<Button>(R.id.play)
val wavTest = MediaPlayer.create(this, R.raw.woodblock_high44_wav)

var playBackSpeed = 3f

play.setOnClickListener {
    wavTest.isLooping = true
    wavTest.playbackParams = PlaybackParams().setSpeed(playBackSpeed)
    wavTest.start()

    wavTest.playbackParams.speed = playBackSpeed
}

Any help or advice would be appreciated.



Solution 1:[1]

I find changing the speed of MediaPlayer works fine, but to make a metronome app I think you should refer to this source code, I think these are good directions to make a metronome app.

Visit link 1: https://github.com/o4oren/android-kotlin-metronome

Visit link 2: https://github.com/zachurchill-root/metronome-kotlin

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 H??ng V?