Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioFlinger(59): RecordThread: buffer overflow when Activity is paused?

Tags:

android

audio

I have an application which consists of a service and an activity that may be started by the service for certain events. The service may create & use the AudioRecord & AudioTrack classes - at which time the application's Activity is displayed. The problem is if the Activity is paused (i.e., onPause() is called) I start getting the RecordThread: buffer overflow errors?

My guess is the AudioRecorder is running in the main thread. And, even though it was created by the service, when the Activity pauses reading stops thus the buffer overflows? Must the AudioRecorder reading be done in a separate thread even though it is running in the service?

Any help would be greatly appreciated, thanks.

like image 884
dchappelle Avatar asked Jan 28 '11 14:01

dchappelle


1 Answers

The RecordThread buffer overflows happen when you aren't pulling the data from the AudioRecord object fast enough.

You should definitely have the loop that pulls data from the AudioRecord object in a sperate thread, and you should stop that thread if your activity gets paused (unless you want to record in the background.)

Here are a couple examples of working implementations:

  • And-dev example
  • StackOverflow example
like image 101
chris Avatar answered Sep 29 '22 11:09

chris