|
24 | 24 | import java.io.FileNotFoundException; |
25 | 25 | import java.io.FileOutputStream; |
26 | 26 | import java.io.IOException; |
27 | | -import java.lang.ref.WeakReference; |
28 | 27 | import java.util.ArrayList; |
29 | 28 | import java.util.List; |
30 | 29 | import java.util.concurrent.ExecutorService; |
@@ -74,7 +73,7 @@ public class AudioRecordUtil implements EncoderListener, FLVListener { |
74 | 73 |
|
75 | 74 | private static final int SAVE_PCM_DATA = 1; |
76 | 75 |
|
77 | | - private WeakReference<IjkMediaPlayer> player; |
| 76 | + private IjkMediaPlayer player; |
78 | 77 | private LinkedBlockingDeque<Byte> playPcmData = new LinkedBlockingDeque<>(); // 内存队列,用于缓存获取到的播放器音频pcm |
79 | 78 |
|
80 | 79 | private class MyHandler extends Handler { |
@@ -231,7 +230,7 @@ public void setMode(VoiceChangerMode mode) { |
231 | 230 | } |
232 | 231 |
|
233 | 232 | public void setPlayer(IjkMediaPlayer player) { |
234 | | - this.player = new WeakReference<>(player); |
| 233 | + this.player = player; |
235 | 234 | } |
236 | 235 |
|
237 | 236 | /** |
@@ -388,7 +387,7 @@ public void run() { |
388 | 387 | if (AudioRecord.ERROR_INVALID_OPERATION != read) { |
389 | 388 | //获取到的pcm数据就是buffer了 |
390 | 389 | if (buffer != null && pcmEncoder != null) { |
391 | | - if (player != null && player.get().isPlaying()) { |
| 390 | + if (player != null && player.isPlaying()) { |
392 | 391 | byte [] playerPcmBytes = onReadPlayerPlayPcm(buffer.length); |
393 | 392 | byte[] aecPcmBytes = GvoiceJNIBridge.cancellation(buffer, playerPcmBytes); |
394 | 393 | if (isRecord) { |
@@ -461,9 +460,9 @@ private class WriteThread extends Thread { |
461 | 460 | @Override |
462 | 461 | public void run() { |
463 | 462 | while (recorderState) { |
464 | | - if (player != null && player.get().isPlaying()) { |
| 463 | + if (player != null && player.isPlaying()) { |
465 | 464 | byte[] data = new byte[204800]; |
466 | | - int len = player.get()._getPcmData(data); |
| 465 | + int len = player._getPcmData(data); |
467 | 466 | if (len > 0) { |
468 | 467 | byte[] playerBytes = new byte[len]; |
469 | 468 | System.arraycopy(data, 0, playerBytes, 0, len); |
|
0 commit comments