Android MediaPlayer.Create() returns null

前端 未结 3 933
青春惊慌失措
青春惊慌失措 2020-12-07 02:28

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         


        
相关标签:
3条回答
  • 2020-12-07 02:50

    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

    • if your device supports the format as indicated by Vasily
    • if the file that you passed in actually exists or has already been created

    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.

    0 讨论(0)
  • 2020-12-07 03:03

    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.

    0 讨论(0)
  • 2020-12-07 03:17

    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

    0 讨论(0)
提交回复
热议问题