android - How to apply threading while streaming a URL.? -
i have code play online radio on shoutcast server. when app launched, streams file , plays it. problem if have no network connection or improper network connection, status of app remains in "streaming" mode forever. want add thread streaming thing should wait 20 seconds, , if not able connect server, should throw event exit app stating "improper network connection". or if there other idea that, appreciated well.. code play media is,
public void playfm() { uri myuri = uri.parse("http://108.166.161.206:8826/;stream.mp3"); try { if (mp == null) { this.mp = new mediaplayer(); } else { mp.stop(); mp.reset(); } mp.setdatasource(this, myuri); // go initialized state mp.setaudiostreamtype(audiomanager.stream_music); streaming=true; progress.setvisibility(view.visible); stream.setvisibility(view.visible); stop.setenabled(false); mp.setonpreparedlistener(this); mp.setonbufferingupdatelistener(this); mp.setonerrorlistener(this); mp.prepareasync(); log.d(tag, "loadclip done"); } catch (throwable t) { log.d(tag, t.tostring()); } }
thanx in advance..
here answer..
irunnable=new runnable() { @override public void run() { //do } };
and in other function
thread th = new thread() { @override public void run() { try { thread.sleep(1000*15); //your code here.. ihandler.postdelayed(irunnable,20*1000); } catch (interruptedexception ie) { } }; th.start(); }
Comments
Post a Comment