Reputation: 26518
I am developing an Android application in which I am showing a ListView
of mp3 files from the sd card.
Now what I want is that when user clicks on any of the mp3 files it should start playing there on the same Activity
. The code which I am using presently is not working for me to play audio files.
My code:
Uri uri = Uri.parse("/sdcard/music/sample.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
But this is something that I want. This is a screen Shot form android gingerbread
Upvotes: 3
Views: 3449
Reputation: 3797
I suppose you should use another approach in case you want audio played in the same activity. I'd better initialize MediaPlayer
object in this activity or as a background service
.
In case of any questions feel free to ask.
UPDATE 1
In general case as I said you either need the MediaPlayer
object in Activity or Music Service
.
Now lets talk about controls.
You can simply put into your layout the block with controls and show/hide it when needed. MediaPlayer provides several convenient callbacks, so you will be able to update progressbar.
So, sum up:
Upvotes: 1
Reputation: 291
see this link here is a good example of getting all the music files and show in list and play when you click any item...
Upvotes: 3