Creating audio file in internal memory in Android -


i want audio file created during audio capture stored in internal memory , played there. getting media player prepare failed() when trying

here's example of how using mediarecorder. first add correct permissions (you need add more if choose use external storage).

<uses-permission android:name="android.permission.record_audio" /> 

this records audio in internal storage:

mediarecorder recorder = new mediarecorder(); recorder.setaudiosource(mediarecorder.audiosource.mic); recorder.setoutputformat(mediarecorder.outputformat.mpeg_4); recorder.setaudioencoder(mediarecorder.audioencoder.amr_nb); recorder.setoutputfile(getfilesdir()+"/audio.m4a"); recorder.prepare(); recorder.start();  ... recorder.stop(); recorder.reset(); recorder.release() 

this plays audio internal storage:

mediaplayer mediaplayer = new mediaplayer(); mediaplayer.setdatasource(getfilesdir()+"/audio.m4a"); mediaplayer.prepare(); mediaplayer.start(); 

getfilesdir() gives path internal files. here's link more information on data storage, http://developer.android.com/guide/topics/data/data-storage.html#filesinternal.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -