https://kotlinlang.org logo
#compose
Title
# compose
d

Dieter Holz

11/12/2020, 9:58 AM
Since alpha07 MediaPlayer doesn’t play sounds anymore This worked before (in alpha06)
Copy code
private val soundPlayer by lazy { MediaPlayer.create(context, R.raw.transporter) }
Copy code
soundPlayer.start()
R.raw.transporter is a mp3-File Any hints?
a

allan.conda

11/12/2020, 10:20 AM
file a bug 🙂 they are pretty responsive there
h

Halil Ozercan

11/12/2020, 10:28 AM
I'm not seeing enough compose context. Can you provide where you are initializing this MediaPlayer and where you are calling
play
d

Dieter Holz

11/12/2020, 11:11 AM
‘context’ is the AppCompatActivity from the ‘MainActivity’ MediaPlayer is initialized in a ‘ViewModel’ in this ‘ViewModel’ there is this function
Copy code
fun playSound(){
    if(!soundPlayer.isPlaying){
        soundPlayer.start()
    }
}
And this is called from the UI, triggered by an onClick of a Button
2 Views