Reputation: 668
I have a list of music files that should be played with my Android application. Actually user selects a list of files to be played for a specified time, and then clicks on 'start button'. Please tell me how I can implement it so that the following requirements are met:
Upvotes: 2
Views: 7901
Reputation: 15018
To play audio files, you can use Android's MediaPlayer
class.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(audioFilePath);
mp.prepare();
mp.start();
This code snippet will load and play a single audio file. Take a look at the documentation for MediaPlayer
to figure out how you might be able to leverage it for what you're trying to accomplish specifically.
Upvotes: 2
Reputation: 234857
In order that the music continue after your application activities exit, you need to implement the playing itself as a Service (specifically, a started service). For playing the music, take a look at MediaPlayer. There is a discussion of using a MediaPlayer in a Service in the Media Player guide topic.
Upvotes: 3