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

前端 未结 4 1295
挽巷
挽巷 2020-12-03 05:11

Hi guys I want to play a certain mp3 file when a text is clicked. For example, I clicked the word \"Nicholas\", the app have to play nicholas.mp3...

Sorry for my mes

4条回答
  •  渐次进展
    2020-12-03 05:21

    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().

提交回复
热议问题