Hi, the following code works for me. I was also getting the "Start failed." error at one point. Fixed it by changing my output file extension from ".3gpp" to ".audio"
-Ben final String path = "/sdcard/recording" + System.currentTimeMillis() + "_" + (int)(Math.random() * 1000)+ ".audio"; final MediaRecorder mr = new MediaRecorder(); mr.setAudioSource(MediaRecorder.AudioSource.MIC); mr.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); mr.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mr.setOutputFile(path); mr.prepare(); mr.start(); //stop recording after 10 seconds Timer t = new Timer(); t.schedule(new TimerTask() { public void run() { //stop recording mr.stop(); mr.release(); } }, 10*1000); On Mar 5, 7:05 pm, jdl <j...@edufone.com> wrote: > Hi Ben, > > Since the tutorial's currently broken, do you mind posting what values > you put in instead of these broken lines: > recorder.getMimeContentType() > MediaStore.Audio.INTERNAL_CONTENT_URI; > > If you got everything working, would you be willing to post your code > (since the tutorial's not yet updated)? > > Thanks, > > AN > > On Feb 26, 4:40 pm, benmccann <benjamin.j.mcc...@gmail.com> wrote: > > > >> each application has its own private data directory / > > >> data/app-private/app-package. I believe your working directory is set > > >> to this directory by default > > > Cool. So it sounds like I should just be able to use a relative path > > from the current location then. Unfortunately, I'm getting the > > following exception (with no clues as to why start is failing): > > > 02-26 14:34:55.132: ERROR/AndroidRuntime(164): > > java.lang.RuntimeException: startfailed. > > 02-26 14:34:55.132: ERROR/AndroidRuntime(164): > > atandroid.media.MediaRecorder.start(Native Method) > > > Here's my code: > > > final MediaRecorder recorder = new MediaRecorder(); > > recorder.setAudioSource(MediaRecorder.AudioSource.MIC); > > recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); > > recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); > > recorder.setOutputFile("test.3gpp"); > > recorder.prepare(); > > recorder.start(); > > > On Feb 26, 12:14 am, Dave Sparks <davidspa...@android.com> wrote: > > > > You can get the path to external storage (e.g. SD card) with > > > Environment.getExternalStorageDirectory(). This is world read/ > > > writable. > > > > Alternatively, each application has its own private data directory / > > > data/app-private/app-package. I believe your working directory is set > > > to this directory by default. This is onboard flash, so it will > > > survive the user ejecting an SD card. However, there is a limited > > > amount to go around, so you don't want to store monster media files > > > there. > > > > On Feb 25, 9:22 pm, benmccann <benjamin.j.mcc...@gmail.com> wrote: > > > > > >> setOutputFile() expects a path to where you want the file stored. > > > > > Yep, figured that much by the method name, but what's a valid path? I > > > > mean I'm figuring it's UNIX-like, but other than that I'm in the > > > > dark. Is there a preferred place for apps to store data? Are there > > > > certain directories that I have permission to write to? What > > > > directories exist on the device by default? It'd be nice for the docs > > > > on data storage to mention any of these > > > > things:http://developer.android.com/guide/topics/data/data-storage.html > > > > > >> You can take a look at the source to SoundRecorder in the open > > > > >> source tree for some working code > > > > > Thanks for the example. This would be a much better example than the > > > > one in the docs that won't compile and implies content must first be > > > > added to a database: > > > > http://developer.android.com/guide/topics/media/index.html > > > > > On Feb 24, 8:03 pm, Dave Sparks <davidspa...@android.com> wrote: > > > > > > setOutputFile() expects a path to where you want the file stored. > > > > > > You can take a look at the source to SoundRecorder in the open source > > > > > tree for some working code: > > > > > >http://android.git.kernel.org/?p=platform/packages/apps/SoundRecorder... > > > > > > On Feb 24, 4:43 pm, benmccann <benjamin.j.mcc...@gmail.com> wrote: > > > > > > > Hi, > > > > > > I'd like to create anaudiorecordinginAndroid. (Actually, I just > > > > > > want access to the mic withoutrecordingit, but it seems that's not > > > > > > supported so I'll have to create arecordingand tail the file). > > > > > > I'm having a very hard time getting started. Mostly I'm just hoping > > > > > > that someone from Google reads this and will update the > > > > > > documentation > > > > > > because the example won't compile - it looks like it's from some > > > > > > previous version of the SDK because there's an error in every other > > > > > > line. I made my best guess as to what the usage should be, but I > > > > > > keep > > > > > > getting a number of different exceptions. > > > > > > One question I had is whether I can just specify an arbitrary path > > > > > > to > > > > > > the MediaRecorder to startrecordingor whether I have to create an > > > > > > entry in the content database. The JavaDoc for > > > > > > MediaRecorder.setOutputFile isn't clear on what it's expecting. > > > > > > > Thanks, > > > > > > Ben --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---