0
我正在使用Visualizer。當我點擊一個按鈕時,它將從AudioTrack獲取數據並顯示。在按鈕,我會調用該函數DrawStart如下:多次致電AudioTrack時發生崩潰
private void DrawStart() {
if (startDrawing) {
initRecorder();
mVisualizerView.link(track);
startRecording();
}
else {
DrawStop();
}
}
它運作良好,約10第一次點擊。這意味着如果我將DrawStart稱爲10次以上,它有錯誤
Fatal signal 11 (SIGSEGV) at 0x00030000 (code=1), thread 8164 (Visualizer)
你能幫我解決嗎?非常感謝。還有我的子fuctions
private void initRecorder() {
_audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxJitter = AudioTrack.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.MODE_IN_COMMUNICATION, SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, maxJitter, AudioTrack.MODE_STREAM);
_audioManager.startBluetoothSco();
_audioManager.setMode(AudioManager.STREAM_VOICE_CALL);
}
private void startRecording() {
recordingThread = new AudioRecordingThread(track,mRecorder, bufferSize,SAMPLE_RATE,new AudioRecordingHandler() {
// Do something
});
recordingThread.start();
}
private void DrawStop() {
if (recordingThread != null) {
recordingThread = null;
}
track.release();
startDrawing = true;
}
而且
public void link(AudioTrack player)
{
if(player == null)
{
throw new NullPointerException("Cannot link to null MediaPlayer");
}
int playerId=player.getAudioSessionId();
// Create the Visualizer object and attach it to our media player.
mVisualizer = new Visualizer(playerId);
mVisualizer.setScalingMode(Visualizer.SCALING_MODE_NORMALIZED);
mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
}