How to play Audio file Mp3 from the server


This question already has an answer here:


try {
    MediaPlayer player = new MediaPlayer();
} catch (Exception e) {
    // TODO: handle exception

Try doing this:

MediaPlayer mp = new MediaPlayer(/*Your-Context*/);
mp.setDataSource(/*MP3 file's Url*/);
mp.setOnPreparedListener(new OnPreparedListener(){
onPrepared(MediaPlayer mp)

If you simply want to open the stream in the default music player (so that you don't have to deal with implementing player buttons, continuing running in the background, etc.), you can use an Intent:

Intent intent = new Intent();
intent.setDataAndType(Uri.parse(""), "audio/mp3");

If you're not currently in an activity, use getBaseContext().startActivity(intent), or something else so that you can call startActivity() on a Context object.

Need Your Help

Distinguishing between delegation, composition and aggregation (Java OO Design)

java oop aggregation composition delegation

I am facing a continuing problem distinguishing delegation, composition and aggregation from each other, and identifying the cases where it's the best to use one over the other.

how to show status bar in ribbon window wpf c#

c# wpf ribbon statusbar

I would like to use the ribbon bar like MS Office 2007 (and greater) in my own applications. Could anyone please provide me with links or references about how I can do this?