Android: Play mp3 file from raw resource on click of a TextView

て烟熏妆下的殇ゞ 提交于 2019-11-27 13:34:00
Konstantin Burov

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!