android - How to use getfiledescriptor with setdatasource -
how should pass in setsourcefile work correctly. want record , play audio concurrently.
here code:
public class mainactivity extends actionbaractivity { string outputfile; mediarecorder recorder; mediaplayer player; parcelfiledescriptor[] pfd; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); recorder = new mediarecorder(); pfd = new parcelfiledescriptor[0]; try { pfd=parcelfiledescriptor.createpipe(); } catch (ioexception e) { e.printstacktrace(); } } public void start(view v) throws ioexception { recorder.setoutputfile(pfd[1].getfiledescriptor());//this working recorder.setaudiosource(mediarecorder.audiosource.mic); recorder.setoutputformat(mediarecorder.outputformat.three_gpp); recorder.setaudioencoder(mediarecorder.outputformat.amr_nb); try { recorder.prepare(); } catch (ioexception e) { e.printstacktrace(); } recorder.start(); mediaplayer player = new mediaplayer(); try { player.setdatasource(pfd[0].getfiledescriptor());// not working }catch (ioexception e) { e.printstacktrace(); } //this exception: // java.io.ioexception: setdatasourcefd failed.: status=0x80000000 plater.prepare(); player.start(); }
is there way transfer audio recorder speaker?