Android MediaPlayer play m3u8 only audio streamming not worked -
hi every 1 write code play fm radio waves. in code there progressbar , 2 buttons 1 of them play , stop. when click play button not happen. how can solve problem? or there suggest me play audio m3u8 files?
code i'm using is:
public class main extends activity implements onclicklistener { private progressbar playseekbar; private button buttonplay; private button buttonstopplay; private mediaplayer player; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); initializeuielements(); initializemediaplayer(); } private void initializeuielements() { playseekbar = (progressbar) findviewbyid(r.id.progressbar1); playseekbar.setmax(100); playseekbar.setvisibility(view.invisible); buttonplay = (button) findviewbyid(r.id.buttonplay); buttonplay.setonclicklistener(this); buttonstopplay = (button) findviewbyid(r.id.buttonstopplay); buttonstopplay.setenabled(false); buttonstopplay.setonclicklistener(this); } public void onclick(view v) { if (v == buttonplay) { startplaying(); } else if (v == buttonstopplay) { stopplaying(); } } private void startplaying() { buttonstopplay.setenabled(true); buttonplay.setenabled(false); playseekbar.setvisibility(view.visible); player.prepareasync(); player.setonpreparedlistener(new onpreparedlistener() { public void onprepared(mediaplayer mp) { player.start(); } }); } private void stopplaying() { if (player.isplaying()) { player.stop(); player.release(); initializemediaplayer(); } buttonplay.setenabled(true); buttonstopplay.setenabled(false); playseekbar.setvisibility(view.invisible); } private void initializemediaplayer() { player = new mediaplayer(); try { player.setdatasource("http://url.m3u8"); } catch (illegalargumentexception e) { e.printstacktrace(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } player.setonbufferingupdatelistener(new onbufferingupdatelistener() { public void onbufferingupdate(mediaplayer mp, int percent) { playseekbar.setsecondaryprogress(percent); log.i("buffering", "" + percent); } }); } @override protected void onpause() { super.onpause(); if (player.isplaying()) { player.stop(); } } }
i solve problem vitamio library. thanks
Comments
Post a Comment