I am having a similar problem with one of my apps. On all other phones I am able to record using MediaRecorder, but on the LG Ally users are reporting crashes.
Did you solve this issue? On Aug 2, 10:56 am, skooter500 <[email protected]> wrote: > Giampaolo > > Thanks for yoru reply, but that's definitely not the problem. In fact > what you suggest is what I already do. doInBackground is only called > once and System.gc gets called once before the recording starts. The > call audioRecord.read blocks until the appropriate number of bytes is > read. Ive tried this as an alternative: > > buffer = new byte[bufferSize]; > int startAt = 0; > > int minBufferSize = > AudioRecord.getMinBufferSize(sampleRate, > AudioFormat.CHANNEL_CONFIGURATION_MONO, > AudioFormat.ENCODING_PCM_16BIT); > audioRecord = new > AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, > AudioFormat.CHANNEL_CONFIGURATION_MONO, > AudioFormat.ENCODING_PCM_16BIT, bufferSize); > audioRecord.startRecording(); > > int bufferReadResult = 0; > while (startAt < bufferSize) > { > > int toRead = 0; > if (startAt + minBufferSize >= bufferSize) > { > toRead = bufferSize - startAt; > } > else > { > toRead = minBufferSize; > } > System.out.println("Starting at " + startAt + " > reading " + toRead + " bytes"); > > bufferReadResult = audioRecord.read(buffer, startAt, > toRead); > System.out.println("Read " + bufferReadResult + " > bytes"); > if (bufferReadResult == > AudioRecord.ERROR_INVALID_OPERATION) > { > message = "ERROR_INVALID_OPERATION returned"; > error = true; > break; > } > if (bufferReadResult == AudioRecord.ERROR_BAD_VALUE) > { > message = "ERROR_BAD_VALUE returned"; > error = true; > break; > } > if (bufferReadResult != toRead) > { > message = "Requested " + toRead + " bytes but read > " + bufferReadResult + " bytes"; > error = true; > } > startAt += bufferReadResult; > } > > This works fine (as does the previous code) on my HTC desire. I'm > waiting for some feedback from my Lg Ally user to let me know if it > works on his phone. If so, problem solved. If not, I'll remove the > lines: > > if (bufferReadResult != toRead) > { > message = "Requested " + toRead + " bytes but read > " + bufferReadResult + " bytes"; > error = true; > } > > And see if that works. Not all Android phones work the same it would > appear. > > Bryan > > On Jul 31, 7:47 pm, "Giampaolo Tomassoni" <[email protected]> > wrote: > > > > protected Void doInBackground(Void... arg0) > > > { > > > System.out.println("Recording started"); > > > audioRecord = null; > > > System.gc(); > > > int totalBytes = bufferSize; > > > try > > > { > > > buffer = new byte[bufferSize]; > > > I'm not an Android expert, nevertheless I have the feeling that the problem > > is in the System.gc() -> new byte[bufferSize] sequence, which seems to me is > > invoked at every sample cycle. > > > In many VM, System.gc() may be a performance killer. It may be this applies > > to theLGAlly, too. > > > If this is the case, the duration of your sampling cycle may be too long to > > sustain the sampling rate, such that the device's hardware buffer gets > > overrun. Then, you're always fetching the maximum size of it, which in case > > of theLGAllycould even be 1024 bytes. If your sampling cycle is long > > enough, you can experience this effect regardless of the sampling rate you > > use. > > > Instead of a "System.gc()" followed by a "new byte[]", I would instead > > suggest to pre-allocate the byte array and possibly every other memory > > resource you need to perform your task. > > > Giampaolo > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

