Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to play audio file in android

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?

like image 573
dIvYaNsH sInGh Avatar asked Sep 03 '11 07:09

dIvYaNsH sInGh


People also ask

How do I open audio files on Android?

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.

How do I play an audio file?

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.


1 Answers

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();     } } 
like image 85
Lalit Poptani Avatar answered Sep 24 '22 01:09

Lalit Poptani