本文介绍了AudioFlinger(59):RecordThread:缓冲区溢出,当活动被暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它由一个服务的且可由特定事件的服务被启动的活性。该服务可以创建和放大器;使用AudioRecord和放大器; AudioTrack类 - 此时将显示应用程序的活动。问题是,如果活动被暂停(即,在onPause()被调用),我开始获取RecordThread:缓冲区溢出错误

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?

我的猜测是AudioRecorder在主线程中运行。和,即使它是由服务创建中,当活动暂停读取从而停止缓冲器溢出?必须在一个单独的线程的AudioRecorder阅读来完成,即使是在服务运行?

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?

任何帮助将是很大的AP preciated,谢谢。

Any help would be greatly appreciated, thanks.

推荐答案

在RecordThread缓冲区溢出发生时,你不拉从AudioRecord对象数据速度不够快。

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

您绝对应该有一个提取数据从AudioRecord对象在sperate线程的循环,你应该停止该线程,如果你的活动被暂停(除非你想在后台进行录制。)

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

这篇关于AudioFlinger(59):RecordThread:缓冲区溢出,当活动被暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 16:20