Question: I have a url: `"http://my_server/song.mp3"`

My code: 

```
String url_song="http://my_server/song.mp3";
MediaPlayer mMediaPlayer=new MediaPlayer();
mMediaPlayer.setDataSource(url_song);
mMediaPlayer.prepare();
mMediaPlayer.start();

```

But it have error (100 0), can not play, i try to download this file and play it in local, it's ok.
So, MediaPlayer have error when play online?

Can someone help me?

Thank all!

Answer: 
Network traffic can never be in the UI thread in Android. Use an `AsyncTask`.

```
new AsyncTask<Void,Void,Void>(){
    public Void doInBackground(Void... v) {
        String url_song="http://my_server/song.mp3";
        MediaPlayer mMediaPlayer=new MediaPlayer();
        mMediaPlayer.setDataSource(url_song);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    }
}.execute();

```

Also, make sure you have the Internet permission in your manifest.
your error log shows IOException so check if the exact file is actually. there also use prepareAsync for network streams as it prepares the stream in the background try this piece of code to. Also implement OnPreparedListener in your class and start the playback in the onPrepared method there.

```
String url_song="http://my_server/song.mp3";
    MediaPlayer mMediaPlayer=new MediaPlayer();
    try{
    mMediaPlayer.setDataSource(url_song);
    mMediaPlayer.prepareAsync();
    }catch(IllegalArgumentException | SecurityException
                | IllegalStateException | IOException e){
     Log.e(TAG, e.toString());
     }

    public void onPrepared(MediaPlayer mp) { mMediaPlayer.start();}

```