WasimSafdar
WasimSafdar

Reputation: 1132

AudioStreaming a mediafile from web

I want to make simple audio streaming application but my this code is throwing exception. Can anybody tell me whats wrong?

***public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       String url = "128.downloadming1.com/bollywood%20mp3/Ekk%20Deewana%20Tha%20(2012)/01%20-%20Kya%20Hai%20Mohabbat.mp3";
        MediaPlayer mp = new MediaPlayer();  
        try {
            mp.setDataSource(url);   
            mp.setAudioStreamType(AudioManager.STREAM_MUSIC);   
            mp.prepare(); 
            mp.start(); 
            } catch (Exception e){ 
            Log.i("Exception", "Exception in streaming mediaplayer e = " + e);
       }
    }***

Upvotes: 0

Views: 55

Answers (2)

manjusg
manjusg

Reputation: 2263

Just adding to Anton's answer. prepare() function on Mediaplayer is synchronous which will block your UI thread. So its better to use setonpreparelistner and start your media player on onpreparelistner().

Upvotes: 1

Anton
Anton

Reputation: 941

You code is ok, but i think, that you must add to url "http://". This must work.

UPD: if this don't work - write you exception.

Upvotes: 0

Related Questions