Java – In the same activity, open mp3 files in the Android default media player

In the same activity, open mp3 files in the Android default media player… here is a solution to the problem.

In the same activity, open mp3 files in the Android default media player

I’m working on an Android app that displays a ListView of mp3 files in an SD card.

Now what I want is that when the user clicks on any mp3 file, it should start playing on the same activity. The code I’m currently using can’t play audio files.

My code:

Uri uri = Uri.parse("/sdcard/music/sample.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

But that’s what I want. Here is a screenshot of Gingerbread for Android

enter image description here

Solution

Seeing this link here is a great example to get all the music files and show them up in the list and play when you click on any item….

  1. Display MusicList and play on itemClick

  2. Another link

Related Problems and Solutions