release AudioPlayer when coming destroy

dev
xufuji456 3 years ago
parent 92040ff073
commit d754d44275
  1. 10
      app/src/main/cpp/audio_player.cpp
  2. 4
      app/src/main/cpp/video_filter.c
  3. 2
      app/src/main/java/com/frank/ffmpeg/AudioPlayer.java
  4. 9
      app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt

@ -29,6 +29,7 @@ extern "C" {
#define MAX_AUDIO_FRAME_SIZE 48000 * 4
int filter_again = 0;
int filter_release = 0;
const char *filter_desc = "superequalizer=6b=4:8b=5:10b=5";
int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink,
@ -280,7 +281,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
}
//read audio frame
while (av_read_frame(pFormatCtx, packet) >= 0) {
while (av_read_frame(pFormatCtx, packet) >= 0 && !filter_release) {
if (packet->stream_index != audio_stream_idx) {
av_packet_unref(packet);
continue;
@ -343,6 +344,9 @@ end:
avformat_close_input(&pFormatCtx);
env->ReleaseStringUTFChars(input_jstr, input_cstr);
env->ReleaseStringUTFChars(filter_jstr, filter_desc);
filter_again = 0;
filter_release = 0;
LOGE(TAG, "audio release...");
}
AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) {
@ -350,3 +354,7 @@ AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) {
filter_again = 1;
filter_desc = env->GetStringUTFChars(filter_jstr, NULL);
}
AUDIO_PLAYER_FUNC(void, release) {
filter_release = 1;
}

@ -384,7 +384,9 @@ end:
audio_track_write_mid = NULL;
ANativeWindow_release(nativeWindow);
(*env)->ReleaseStringUTFChars(env, filePath, file_name);
LOGE(TAG, "do release...");
again = 0;
release = 0;
LOGE(TAG, "video release...");
return ret;
}

@ -19,6 +19,8 @@ public class AudioPlayer {
public native void again(String filterDesc);
public native void release();
//using OpenSL ES to play
public native void playAudio(String audioPath);

@ -109,4 +109,13 @@ class EqualizerActivity : BaseActivity(), OnSeeBarListener {
override fun onSelectedFile(filePath: String) {
audioPath = filePath
}
override fun onDestroy() {
super.onDestroy()
if (filterThread != null) {
mAudioPlayer!!.release()
filterThread?.interrupt()
filterThread = null
}
}
}

Loading…
Cancel
Save