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
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...
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.