dchappelle
dchappelle

Reputation: 1710

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

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.

Upvotes: 10

Views: 18309

Answers (2)

Teknia
Teknia

Reputation: 151

Although an old question, I wish I knew this answer when starting to work with Services, so I will log it for future reference by others:

An often overlooked but VERY important point regarding Services is the fact that they do not automatically spawn their own threads, but runs on the main GUI thread. This is very counter-intuitive when considering the word 'service', but nonetheless true. (See the first 'Caution' section at http://developer.android.com/guide/topics/fundamentals/services.html).

You may also want to consider extending the IntentService class instead of the Service class which will "...create[s] a default worker thread that executes all intents ... separate from your application's main thread." (http://developer.android.com/guide/topics/fundamentals/services.html)

Hope someone finds this useful!

Upvotes: 1

chris
chris

Reputation: 1045

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:

Upvotes: 9

Related Questions