Wednesday, 15 April 2015

java - Android recording app, recording doesn't begin -



java - Android recording app, recording doesn't begin -

i'm new java/android , have been having problem simple recording app. have been next tutorial here , while think @ end, app not work. here .java code:

public class mainactivity extends activity { private mediarecorder audiorecorder; private string outfile = null; private button record, stop, play; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); record = (button)findviewbyid(r.id.recordbutton); stop = (button)findviewbyid(r.id.stopbutton); play = (button)findviewbyid(r.id.playbutton); stop.setenabled(false); play.setenabled(false); outfile = environment.getexternalstoragedirectory().getabsolutepath()+"/myrec.3gp"; audiorecorder = new mediarecorder(); audiorecorder.reset(); audiorecorder.setaudiosource(mediarecorder.audiosource.mic); audiorecorder.setoutputformat(mediarecorder.outputformat.three_gpp); audiorecorder.setaudioencoder(mediarecorder.outputformat.amr_nb); audiorecorder.setoutputfile(outfile); } public void record(view view){ seek { audiorecorder.prepare(); audiorecorder.start(); } catch(illegalstateexception ise){ ise.printstacktrace(); } catch(ioexception ioe) { ioe.printstacktrace(); } record.setenabled(false); stop.setenabled(true); toast.maketext(getapplicationcontext(), "recording...", toast.length_short).show(); } public void stop(view view){ audiorecorder.stop(); audiorecorder.release(); audiorecorder = null; stop.setenabled(false); play.setenabled(true); toast.maketext(getapplicationcontext(), "recorded successfully.", toast.length_short).show(); } public void play(view view) throws illegalargumentexception, securityexception, illegalstateexception, ioexception{ mediaplayer mp = new mediaplayer(); mp.setdatasource(outfile); mp.prepare(); mp.start(); toast.maketext(getapplicationcontext(), "playing...", toast.length_short).show(); } }

i have made sure include proper uses-permissions in xml file external storage , recording audio.

when run app, don't warnings, press record button , nil happens. can help me see glaring have overlooked? much!

i using win7 android studio , testing on motorola moto g w/ android 4.4.

i answering own question code completeness, credit goes immibis 1 directed me there.

i had not set buttons on click. needed alter xml phone call methods on click. added line each button in xml (where record method name).

android:onclick="record"

thanks 1 time again immibis help on this.

java android android-studio

No comments:

Post a Comment