media player - Voice does not record when playing video in video view in android -
i developing application want start recording voice on button click, , want star playing video in video view @ same time. app works on androdi 4.2 , android 5.1 not work on latest device android 7.0. here code
public class mainactivity extends activity { button start,stop,play; boolean recording=false; string press_value="exit"; private static final string audio_recorder_folder = "audiorecorder"; boolean let_start_recording=true; imageview startiv,profileiv; boolean recording_is_in_progress=false; videoview vv ; mediaplayer mplayer; relativelayout mainrel; ///new media player string audiosavepathindevice = null; mediarecorder mediarecorder ; random random ; string randomaudiofilename = "abcdefghijklmnop"; public static final int requestpermissioncode = 1; mediaplayer mediaplayer ; @suppresswarnings("deprecation") @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); startiv=(imageview)findviewbyid(r.id.imageview1); profileiv=(imageview)findviewbyid(r.id.imageview3); vv = (videoview)findviewbyid(r.id.your_video_view); mainrel=(relativelayout)findviewbyid(r.id.main_rel); recording_is_in_progress=false; stopanimation(); profileiv.setonclicklistener(new onclicklistener() { public void onclick(view v) { if(let_start_recording) { let_start_recording=false; startiv.setimageresource(r.drawable.recorder_stop_circle); startrecording(); recording_is_in_progress=true; startanimation(); } else { let_start_recording=true; startiv.setimageresource(r.drawable.recorder_start_circle); stoprecording(); recording_is_in_progress=false; stopanimation();//stop animation once press button } } }); //start & stop recording startiv.setonclicklistener(new onclicklistener() { public void onclick(view v) { if(let_start_recording) { let_start_recording=false; startiv.setimageresource(r.drawable.recorder_stop_circle); startrecording(); recording_is_in_progress=true; startanimation(); } else { let_start_recording=true; startiv.setimageresource(r.drawable.recorder_start_circle); stoprecording(); recording_is_in_progress=false; stopanimation();//stop animation once press button } } }); }//eof oncreate //(((( start animation )))) public void startanimation() { // vv.setvisibility(view.visible); startiv.setvisibility(view.visible); mainrel.setvisibility(view.visible); profileiv.setvisibility(view.gone); //video loop vv.setoncompletionlistener(new mediaplayer.oncompletionlistener() { public void oncompletion(mediaplayer mp) { vv.start(); //need make transition seamless. } }); // uri uri = uri.parse(r.drawable.sheep_video); uri uri= uri.parse("android.resource://com.pac.myapp/raw/sheep_video"); vv.setvideouri(uri); vv.requestfocus(); vv.start(); vv.setvideouri(uri.parse("android.resource://" + getpackagename() + "/" + r.drawable.sheep_video)); vv.setonpreparedlistener(new onpreparedlistener() { @override public void onprepared(mediaplayer mp) { mp.setlooping(true); /// showtoast("video compelted"); } }); } public void stopanimation() { if(vv.isplaying()) vv.stopplayback(); //vv.setvisibility(view.invisible); startiv.setvisibility(view.gone); mainrel.setvisibility(view.invisible); profileiv.setvisibility(view.visible); } private string getfilename() { string filepath = environment.getexternalstoragedirectory().getpath(); file file = new file(filepath, audio_recorder_folder); if (!file.exists()) { file.mkdirs(); } simpledateformat dateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss"); string filename = dateformat.format(new date()); filename="voice "+filename+".wav"; return (file.getabsolutepath() + file.separator + filename); //return (file.getabsolutepath() + "/" + system.currenttimemillis() + ".wav"); } private void startrecording() { audiosavepathindevice = getfilename(); // environment.getexternalstoragedirectory().getabsolutepath() + "/" + // createrandomaudiofilename(5) + "audiorecording.3gp"; mediarecorderready(); try { mediarecorder.prepare(); mediarecorder.start(); } catch (illegalstateexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } private void stoprecording() { mediarecorder.stop(); } public void mediarecorderready(){ mediarecorder=new mediarecorder(); mediarecorder.setaudiosource(mediarecorder.audiosource.mic); mediarecorder.setoutputformat(mediarecorder.outputformat.three_gpp); mediarecorder.setaudioencoder(mediarecorder.outputformat.amr_nb); mediarecorder.setoutputfile(audiosavepathindevice); } public void onbackpressed() { if(recording_is_in_progress=true) { //if(recorder!=null) //stoprecording(); finish(); } } public void home(view v) { //intent i=new intent(v.getcontext(),mainactivity.class); //startactivity(i); //finish(); } public void voice_list(view v) { if(recording_is_in_progress==false) { intent i=new intent(v.getcontext(),savedvoicelist.class); startactivity(i); finish(); } } public void about_us(view v) { //showtoast("status = "+recording_is_in_progress); if(recording_is_in_progress==false) { intent i=new intent(v.getcontext(),aboutusactivity.class); startactivity(i); finish(); } } public void showtoast(string str) { toast.maketext(getapplicationcontext(), str, toast.length_long).show(); } }//eof activit
probably have request android.permission.record_audio
permission able record after android 6 version.
please check the document
Comments
Post a Comment