user672512
user672512

Reputation: 63

Accessing music files into my application programmatically

How can I access music files in the device into my application programmatically?

Upvotes: 2

Views: 7207

Answers (2)

Nicolai Buch-Andersen
Nicolai Buch-Andersen

Reputation: 593

Another approach could be to use the MediaStore content provider to find your music: http://developer.android.com/reference/android/provider/MediaStore.html.

There's a DATA field in the MediaColumns that holds the data stream for the media file.

Google has an example of reading images from the MediaStore a bit more than half way down this page: http://developer.android.com/guide/topics/providers/content-providers.html. You should be able to adopt the code to read music without too much trouble, I think.

EDIT: Google has re-written the documentation on content providers. The example I referred to above doesn't seem to exist any longer. But once you have an URI for your media, you should be able to get an Input stream by using:

InputStream is = getContentResolver().openInputStream(uri);

Upvotes: 7

Lunchbox
Lunchbox

Reputation: 2156

Depending on where your files are stored you can use:

Environment.getExternalStorageDirectory();

or:

Environment.getDataDirectory();

Both will give you the root path to their respective data. i.e. getExternalStorageDirectory() will gives me /mnt/sdcard/ on my Evo 4G since my SD card is registered as external storage for the device.

After that you have to know where your files are and make your way to that folder.

Upvotes: 1

Related Questions