I am developing an Android App that plays some sounds. For that I am creating an object of MediaPlayer. Below is the code:
mp = MediaPlayer.create(this, R.ra
null
seems to be communicating that something went wrong. Since Google shows this as the first result for "android mediaplayer.create() returns null", my recommendation would be to go through your code and check
In my case I had created an empty file before passing it to Mediaplayer.create
. This worked fine on my emulated device, but crashed on my personal device.
Your file uses WAVE 8,000Hz MP3 8 kbit/s format, while android supports only 8- and 16-bit linear PCM: http://developer.android.com/guide/appendix/media-formats.html.
Try fixing your file.
It can happen that it returns null
because the device doesn't support playing audio i.e watch
.
To check if device supports MediaPlayer you can do a null check on MediaPlayer.create()
I found it on google santa-tracker app