From 310a4cc1b3b96dcccf30739224a9ba7277c60512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?whalensun=28=E5=AD=99=E4=BC=9F=29?= <532125505@qq.com> Date: Thu, 23 Nov 2023 11:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=A0=E9=80=92=E7=9A=84pl?= =?UTF-8?q?ayer=E5=BC=B1=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0596759efd090575083f9b85fb841a354bbe54e8 --- .../iot/video/link/util/audio/AudioRecordUtil.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sdk/video-link-android/src/main/java/com/tencent/iot/video/link/util/audio/AudioRecordUtil.java b/sdk/video-link-android/src/main/java/com/tencent/iot/video/link/util/audio/AudioRecordUtil.java index ae438eddf..dc2e4df7e 100644 --- a/sdk/video-link-android/src/main/java/com/tencent/iot/video/link/util/audio/AudioRecordUtil.java +++ b/sdk/video-link-android/src/main/java/com/tencent/iot/video/link/util/audio/AudioRecordUtil.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; @@ -73,7 +74,7 @@ public class AudioRecordUtil implements EncoderListener, FLVListener { private static final int SAVE_PCM_DATA = 1; - private IjkMediaPlayer player; + private WeakReference player; private LinkedBlockingDeque playPcmData = new LinkedBlockingDeque<>(); // 内存队列,用于缓存获取到的播放器音频pcm private class MyHandler extends Handler { @@ -230,7 +231,7 @@ public void setMode(VoiceChangerMode mode) { } public void setPlayer(IjkMediaPlayer player) { - this.player = player; + this.player = new WeakReference<>(player); } /** @@ -387,7 +388,7 @@ public void run() { if (AudioRecord.ERROR_INVALID_OPERATION != read) { //获取到的pcm数据就是buffer了 if (buffer != null && pcmEncoder != null) { - if (player != null && player.isPlaying()) { + if (player != null && player.get().isPlaying()) { byte [] playerPcmBytes = onReadPlayerPlayPcm(buffer.length); byte[] aecPcmBytes = GvoiceJNIBridge.cancellation(buffer, playerPcmBytes); if (isRecord) { @@ -460,9 +461,9 @@ private class WriteThread extends Thread { @Override public void run() { while (recorderState) { - if (player != null && player.isPlaying()) { + if (player != null && player.get().isPlaying()) { byte[] data = new byte[204800]; - int len = player._getPcmData(data); + int len = player.get()._getPcmData(data); if (len > 0) { byte[] playerBytes = new byte[len]; System.arraycopy(data, 0, playerBytes, 0, len);