i am trying to play music or mp3 on click of an action button but none is working since most of the tutorials are based on button listeners. i need help regarding how to play music on click of an option menu or action bar menu. Can anyone please help me regarding this problem.
Asked
Active
Viewed 44 times
-1
-
provide the code and xml you wrote so far for menu – Jul 23 '18 at 17:38
1 Answers
0
Here is a recommended solution to playing a mp3:
Link: Simple mediaplayer play mp3 from file path?
String filePath =
Environment.getExternalStorageDirectory()+"/yourfolderNAme/yopurfile.mp3";
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare();
mediaPlayer.start()
and this play from raw folder.
int resID=myContext.getResources().getIdentifier(playSoundName,"raw",myContext.getPackageName());
MediaPlayer mediaPlayer = MediaPlayer.create(myContext,resID);
mediaPlayer.prepare();
mediaPlayer.start();

Nigel Brown
- 440
- 2
- 13