java – MediaPlayer. Create() always returns null

I've used a media player before and I've never encountered this problem Whenever I try to use mediaplayer When create(), the method will be null, and I can't play my voice Is there anything I miss?

public class Game extends Activity
{
    private MediaPlayer mp = null;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game);

        mp = MediaPlayer.create(getBaseContext(),R.raw.sound);
    }
}

My sound Mp3 is in my original folder. I put the sound in the folder in eclipse Please help, because I've played sounds before, which really bothers me:(

Solution

If one way fails, the create () API will return null

The reason in this case is due to a corrupted MP3 file

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>