SamRowley
SamRowley

Reputation: 3485

Play mp3 file given a url directly to the mp3

I want to be able to play an mp3 file in my android application given a url (e.g. http://www.somedomain.com/audio.mp3).

This I think should be used to get a byte array using an InputStream maybe but I'm not totally sure, which then can be used with a MediaPlayer object.

Upvotes: 0

Views: 1530

Answers (2)

I found in practical life that the MediaPlayer can play just about any MP3 URL if you take care to reformat any Space characters (0x20) into "%20". I tried that URLEncoder and some other filters to little gain but simply converting those spaces before presenting the URL to MediaPlayer will take you far.

In a String you can easily substitute stuff:

mediaPlayer.setDataSource(urlString.replace(" ", "%20"));

Upvotes: 0

ba__friend
ba__friend

Reputation: 5903

Read through the SDK pages. Playing from a File or Stream

Upvotes: 1

Related Questions