android - Change the URI on click -
i'm making radio app, app kinda finished. want let user change station clicking button specified each station.
update: put in more code.
so thinking this? i'm not sure put it.
public void onclicklistener (view v) { if (v == rduhok) { kradio.setdatasource("http://87.106.215.231:9992"); } else if (v == rvin) { kradio.setdatasource("http://93.91.197.214:1234"); } }
right have link station says myuri, , app working expected. want able change uri clicking button.
public class kurdradioactivity extends activity implements onclicklistener { private progressbar playseekbar; private button buttonplay; private button buttonstopplay; private button rduhok; private button rvin; private mediaplayer kradio; /** 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); rduhok = (button) findviewbyid(r.id.rduhok); rduhok.setonclicklistener(this); rvin = (button) findviewbyid(r.id.rvin); rvin.setonclicklistener(this); buttonstopplay = (button) findviewbyid(r.id.buttonstopplay); buttonstopplay.setvisibility(view.gone); buttonstopplay.setonclicklistener(this); } public void onclick(view v) { vibrator vib = (vibrator) getsystemservice(context.vibrator_service); vib.vibrate(50); if (v == buttonplay) { startplaying(); } else if (v == buttonstopplay) { stopplaying(); } } private void startplaying() { buttonstopplay.setvisibility(view.visible); buttonplay.setvisibility(view.gone); playseekbar.setvisibility(view.visible); kradio.prepareasync(); kradio.setonpreparedlistener(new onpreparedlistener() { public void onprepared(mediaplayer mp) { playseekbar.setvisibility(view.invisible); kradio.start(); } }); } private void stopplaying() { if (kradio.isplaying()) { kradio.stop(); kradio.release(); initializemediaplayer(); } buttonplay.setvisibility(view.visible); buttonstopplay.setvisibility(view.gone); playseekbar.setvisibility(view.invisible); } private void initializemediaplayer() { kradio = new mediaplayer(); try { kradio.setdatasource("http://87.106.215.231:9992"); } catch (illegalargumentexception e) { e.printstacktrace(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } kradio.setonbufferingupdatelistener(new onbufferingupdatelistener() { public void onbufferingupdate(mediaplayer mp, int percent) { playseekbar.setsecondaryprogress(percent); log.i("buffering", "" + percent); } }); } @override protected void onpause() { super.onpause(); if (this.isfinishing()) { kradio.stop(); } }
just want im new in programing , im learning, help.
i'm making radio app, app kinda finished. want let user change station clicking button specified each station. update: put in more code. so thinking this? i'm not sure put it. right have link station says myuri, , app working expected. want able change uri clicking button. just want im new in programing , im learning, help. | ||||
onclick
listener. 1 of basic things can in android... can save lot of time reading developers site instead of asking here :) – alex lockwood jul 7 '12 @ 14:57