I have a mp3 file in my android mobile, lets it's a xyz.mp3 somewhere in my sdcard. How to play it through my application?
To play audio or video files in Android, the Android multimedia framework includes the support of MediaPlayer APIs. So, by using MediaPlayer APIs, you can play audio/video files from your Android filesystem or play files from your Application's resource file or even you can stream audio/video files just like Spotify.
Open File Manager and navigate to the folder where the audio file is located. Drag the audio file icon from File Manager and drop it on the Audio main window. The Selected file is opened. If Automatically play audio file on Open is selected in the Options-Play dialog box, the audio file starts playing.
Simply you can use MediaPlayer
and play the audio file. Check out this nice example for playing Audio:
public void audioPlayer(String path, String fileName){ //set up MediaPlayer MediaPlayer mp = new MediaPlayer(); try { mp.setDataSource(path + File.separator + fileName); mp.prepare(); mp.start(); } catch (Exception e) { e.printStackTrace(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With