Play mp3 file from raw resource on click of a TextView Play mp3 file from raw resource on click of a TextView android android

Play mp3 file from raw resource on click of a TextView


You need to pass in a context instance into MediaPlayer.create method:

MediaPlayer mPlayer = MediaPlayer.create(PlayWorld.this, R.raw.aaanicholas);

Also, after the create() call, prepare is already executed, so you don't need to execute it explicitly, just invoke start() right after create().


When you create the mPlayer object you should pass it the Context, which is in your case PlayWord.this.


MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile);    mPlayer.start();