release audioTrack when exit playing

dev
xufuji456 3 years ago
parent c9c3529f2f
commit 4fccf3f6a6
  1. 2
      app/src/main/cpp/audio_player.cpp
  2. 12
      app/src/main/java/com/frank/ffmpeg/AudioPlayer.java

@ -344,6 +344,8 @@ end:
avformat_close_input(&pFormatCtx); avformat_close_input(&pFormatCtx);
env->ReleaseStringUTFChars(input_jstr, input_cstr); env->ReleaseStringUTFChars(input_jstr, input_cstr);
env->ReleaseStringUTFChars(filter_jstr, filter_desc); env->ReleaseStringUTFChars(filter_jstr, filter_desc);
jmethodID releaseMethod = env->GetMethodID(player_class, "releaseAudioTrack", "()V");
env->CallVoidMethod(thiz, releaseMethod);
filter_again = 0; filter_again = 0;
filter_release = 0; filter_release = 0;
LOGE(TAG, "audio release..."); LOGE(TAG, "audio release...");

@ -14,6 +14,8 @@ public class AudioPlayer {
System.loadLibrary("media-handle"); System.loadLibrary("media-handle");
} }
private AudioTrack mAudioTrack;
//using AudioTrack to play //using AudioTrack to play
public native void play(String audioPath, String filterDesc); public native void play(String audioPath, String filterDesc);
@ -46,7 +48,15 @@ public class AudioPlayer {
int bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat); int bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);
return new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, audioFormat, mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, audioFormat,
bufferSizeInBytes, AudioTrack.MODE_STREAM); bufferSizeInBytes, AudioTrack.MODE_STREAM);
return mAudioTrack;
}
public void releaseAudioTrack() {
if (mAudioTrack != null) {
mAudioTrack.release();
mAudioTrack = null;
}
} }
} }

Loading…
Cancel
Save