1.关于AudioRecord中缓冲区的大小大家如何设置
2.设置了setRecordPositionUpdateListener为何没有被调用到
3.setPositionNotificationPeriod(int periodInFrames)这个peroidInFrames参数如何设置
2.设置了setRecordPositionUpdateListener为何没有被调用到
3.setPositionNotificationPeriod(int periodInFrames)这个peroidInFrames参数如何设置
解决方案 »
- 如何实现点击拨号盘搜索出对应联系人?
- android上 如何增加相应的语言包呢?
- 最近在做播放器例子,有几个问题要请教各位!!!!!!!!!!!!!!!
- 多个widget换肤问题响应速度慢
- webview 怎么实现window.open 创建新窗口的
- 求教 用asmack向openfire注册时 如何增加vcard信息
- 为什么用FTP4J做的客户端只能从FTP服务器下载,但不能向FTP服务器上传呢?
- 如何通过 ttyS0 控制Android
- Android 怎么利用Socket做在线视频的播放
- 在线跪等!!求大神帮忙看看!!!!
- 畅谈一下GO桌面特效的实现---欢迎讨论
- android 调用 php nusoap 的问题
你给的这一份不是使用设置listenner来解决的,而且他参数都是写死的,缓冲区大小用getMin..
public void testAudioRecordOP() throws Exception {
227 final int SLEEP_TIME = 10;
228 final int RECORD_TIME = 10000;
229 assertEquals(AudioRecord.STATE_INITIALIZED, mAudioRecord.getState());
230
231 int erInFrames = mAudioRecord.getSampleRate() / 2;
232 assertEquals(AudioRecord.SUCCESS,
233 mAudioRecord.setNotificationMarkerPosition(erInFrames));
234 assertEquals(erInFrames, mAudioRecord.getNotificationMarkerPosition());
235 int periodInFrames = mAudioRecord.getSampleRate();
236 assertEquals(AudioRecord.SUCCESS,
237 mAudioRecord.setPositionNotificationPeriod(periodInFrames));
238 assertEquals(periodInFrames, mAudioRecord.getPositionNotificationPeriod());
239 OnRecordPositionUpdateListener listener = new OnRecordPositionUpdateListener() {
240
241 public void onMarkerReached(AudioRecord recorder) {
242 mIsOnMarkerReachedCalled = true;
243 }
244
245 public void onPeriodicNotification(AudioRecord recorder) {
246 mIsOnPeriodicNotificationCalled = true;
247 }
248 };
249 mAudioRecord.setRecordPositionUpdateListener(listener);
250
251 // use byte array as buffer
252 final int BUFFER_SIZE = 102400;
253 byte[] byteData = new byte[BUFFER_SIZE];
254 long time = System.currentTimeMillis();
255 mAudioRecord.startRecording();
256 assertEquals(AudioRecord.RECORDSTATE_RECORDING, mAudioRecord.getRecordingState());
257 while (System.currentTimeMillis() - time < RECORD_TIME) {
258 Thread.sleep(SLEEP_TIME);
259 mAudioRecord.read(byteData, 0, BUFFER_SIZE);
260 }
261 mAudioRecord.stop();
262 assertEquals(AudioRecord.RECORDSTATE_STOPPED, mAudioRecord.getRecordingState());
263 assertTrue(mIsOnMarkerReachedCalled);
264 assertTrue(mIsOnPeriodicNotificationCalled);
265 reset();
266
267 // use short array as buffer
268 short[] shortData = new short[BUFFER_SIZE];
269 time = System.currentTimeMillis();
270 mAudioRecord.startRecording();
271 assertEquals(AudioRecord.RECORDSTATE_RECORDING, mAudioRecord.getRecordingState());
272 while (System.currentTimeMillis() - time < RECORD_TIME) {
273 Thread.sleep(SLEEP_TIME);
274 mAudioRecord.read(shortData, 0, BUFFER_SIZE);
275 }
276 mAudioRecord.stop();
277 assertEquals(AudioRecord.RECORDSTATE_STOPPED, mAudioRecord.getRecordingState());
278 assertTrue(mIsOnMarkerReachedCalled);
279 assertTrue(mIsOnPeriodicNotificationCalled);
280 reset();
281
282 // use ByteBuffer as buffer
283 ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
284 time = System.currentTimeMillis();
285 mAudioRecord.startRecording();
286 assertEquals(AudioRecord.RECORDSTATE_RECORDING, mAudioRecord.getRecordingState());
287 while (System.currentTimeMillis() - time < RECORD_TIME) {
288 Thread.sleep(SLEEP_TIME);
289 mAudioRecord.read(byteBuffer, BUFFER_SIZE);
290 }
291 mAudioRecord.stop();
292 assertEquals(AudioRecord.RECORDSTATE_STOPPED, mAudioRecord.getRecordingState());
293 assertTrue(mIsOnMarkerReachedCalled);
294 assertTrue(mIsOnPeriodicNotificationCalled);
295 reset();
296
297 // use handler
298 final Handler handler = new Handler(Looper.getMainLooper()) {
299 @Override
300 public void handleMessage(Message msg) {
301 mIsHandleMessageCalled = true;
302 super.handleMessage(msg);
303 }
304 };
305
306 mAudioRecord.setRecordPositionUpdateListener(listener, handler);
307 time = System.currentTimeMillis();
308 mAudioRecord.startRecording();
309 assertEquals(AudioRecord.RECORDSTATE_RECORDING, mAudioRecord.getRecordingState());
310 while (System.currentTimeMillis() - time < RECORD_TIME) {
311 Thread.sleep(SLEEP_TIME);
312 mAudioRecord.read(byteData, 0, BUFFER_SIZE);
313 }
314 mAudioRecord.stop();
315 assertEquals(AudioRecord.RECORDSTATE_STOPPED, mAudioRecord.getRecordingState());
316 assertTrue(mIsOnMarkerReachedCalled);
317 assertTrue(mIsOnPeriodicNotificationCalled);
318 // The handler argument is only ever used for getting the associated Looper
319 assertFalse(mIsHandleMessageCalled);
320
321 mAudioRecord.release();
322 assertEquals(AudioRecord.STATE_UNINITIALIZED, mAudioRecord.getState());
323 }
int periodInFrames = mAudioRecord.getSampleRate();
assertEquals(AudioRecord.SUCCESS,mAudioRecord.setPositionNotificationPeriod(periodInFrames));
这个会不会导致在不同的机器出现不同结果,而导致缓冲区溢出呢?是否有更好的计算方式?
http://blog.csdn.net/wildwolf_007/article/details/6635120
我发现了这个博客,但是里面的回调函数却没法被调用到?你能看下吗?