suddenly my app doesnt play a sound when I call mediaPlayer.start()
.
I get following error in log:
2020-05-29 20:43:57.165 4719-1953/? E/AudioSystem: invalid attributes { Content type: AUDIO_CONTENT_TYPE_UNKNOWN Usage: AUDIO_USAGE_UNKNOWN Source: -1 Flags: 0x800 Tags: } when converting to stream
I am doing this one when the app starts:
mMediaPlayer = MediaPlayer.create(context, R.raw.restaurant_order_received)
Thanks for help
You need to provide a resourceID. Try this:
var resID = context?.resources?.getIdentifier("YOUR_FILE_NAME", "raw", context.packageName)
resID?.let {
// No fike found when it == 0
if (it == 0) {
val errorString = "Error occured."
Snackbar.make(view, errorString, 2000).show()
return
}
mediaPlayer = MediaPlayer.create(context, it)
mediaPlayer?.start()
return
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With