show the result of silence detection

pull/190/head
xufuji456 4 years ago
parent 272f8c853b
commit e216dd7113
  1. 21
      app/src/main/cpp/ffmpeg_cmd.c
  2. 5
      app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java
  3. 13
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt
  4. 21
      app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java
  5. 1
      app/src/main/java/com/frank/ffmpeg/listener/OnHandleListener.kt

@ -54,6 +54,16 @@ FFMPEG_FUNC(void, cancelTaskJni, jint cancel) {
cancel_task(cancel); cancel_task(cancel);
} }
void msg_callback(const char* format, va_list args) {
if (ff_env && msg_method) {
char *ff_msg = (char*) malloc(sizeof(char) * 1024);
vsprintf(ff_msg, format, args);
jstring jstr = (*ff_env)->NewStringUTF(ff_env, ff_msg);
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, msg_method, jstr);
free(ff_msg);
}
}
void log_callback(void* ptr, int level, const char* format, va_list args) { void log_callback(void* ptr, int level, const char* format, va_list args) {
switch (level) { switch (level) {
case AV_LOG_WARNING: case AV_LOG_WARNING:
@ -61,16 +71,13 @@ void log_callback(void* ptr, int level, const char* format, va_list args) {
break; break;
case AV_LOG_INFO: case AV_LOG_INFO:
ALOGI(FFMPEG_TAG, format, args); ALOGI(FFMPEG_TAG, format, args);
if (format && strncmp("silence", format, 7) == 0) {
msg_callback(format, args);
}
break; break;
case AV_LOG_ERROR: case AV_LOG_ERROR:
ALOGE(FFMPEG_TAG, format, args); ALOGE(FFMPEG_TAG, format, args);
if (ff_env && msg_method) { msg_callback(format, args);
char *ff_msg = (char*) malloc(sizeof(char) * 1024);
vsprintf(ff_msg, format, args);
jstring jstr = (*ff_env)->NewStringUTF(ff_env, ff_msg);
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, msg_method, jstr);
free(ff_msg);
}
break; break;
default: default:
break; break;

@ -180,6 +180,11 @@ public class FFmpegCmd {
public static void onMsgCallback(String msg) { public static void onMsgCallback(String msg) {
if (msg != null && !msg.isEmpty()) { if (msg != null && !msg.isEmpty()) {
Log.e(TAG, "from native msg=" + msg); Log.e(TAG, "from native msg=" + msg);
// silence detect callback
if (msg.startsWith("silence") && mProgressListener != null) {
mProgressListener.onMsg(msg);
}
} }
} }

@ -11,6 +11,7 @@ import android.util.Log
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import android.widget.Toast
import java.io.File import java.io.File
import java.util.ArrayList import java.util.ArrayList
@ -22,9 +23,11 @@ import com.frank.ffmpeg.handler.FFmpegHandler
import com.frank.ffmpeg.util.FFmpegUtil import com.frank.ffmpeg.util.FFmpegUtil
import com.frank.ffmpeg.util.FileUtil import com.frank.ffmpeg.util.FileUtil
import com.frank.ffmpeg.handler.FFmpegHandler.MSG_INFO
import com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN import com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN
import com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH import com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH
import com.frank.ffmpeg.handler.FFmpegHandler.MSG_PROGRESS import com.frank.ffmpeg.handler.FFmpegHandler.MSG_PROGRESS
import java.lang.StringBuilder
/** /**
* Using ffmpeg command to handle audio * Using ffmpeg command to handle audio
@ -43,6 +46,7 @@ class AudioHandleActivity : BaseActivity() {
private val outputPath1 = PATH + File.separator + "output1.mp3" private val outputPath1 = PATH + File.separator + "output1.mp3"
private val outputPath2 = PATH + File.separator + "output2.mp3" private val outputPath2 = PATH + File.separator + "output2.mp3"
private var isJointing = false private var isJointing = false
private var infoBuilder: StringBuilder? = null
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
private val mHandler = object : Handler() { private val mHandler = object : Handler() {
@ -61,6 +65,11 @@ class AudioHandleActivity : BaseActivity() {
FileUtil.deleteFile(outputPath1) FileUtil.deleteFile(outputPath1)
FileUtil.deleteFile(outputPath2) FileUtil.deleteFile(outputPath2)
} }
if (infoBuilder != null) {
Toast.makeText(this@AudioHandleActivity,
infoBuilder.toString(), Toast.LENGTH_LONG).show()
infoBuilder = null
}
} }
MSG_PROGRESS -> { MSG_PROGRESS -> {
val progress = msg.arg1 val progress = msg.arg1
@ -72,6 +81,10 @@ class AudioHandleActivity : BaseActivity() {
txtProgress!!.visibility = View.INVISIBLE txtProgress!!.visibility = View.INVISIBLE
} }
} }
MSG_INFO -> {
if (infoBuilder == null) infoBuilder = StringBuilder()
infoBuilder?.append(msg.obj)
}
else -> { else -> {
} }
} }

@ -8,6 +8,8 @@ import com.frank.ffmpeg.listener.OnHandleListener;
import com.frank.ffmpeg.model.MediaBean; import com.frank.ffmpeg.model.MediaBean;
import com.frank.ffmpeg.tool.JsonParseTool; import com.frank.ffmpeg.tool.JsonParseTool;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
/** /**
@ -26,7 +28,9 @@ public class FFmpegHandler {
public final static int MSG_CONTINUE = 2012; public final static int MSG_CONTINUE = 2012;
public final static int MSG_TOAST = 4562; public final static int MSG_TOAST = 5432;
public final static int MSG_INFO = 2222;
private Handler mHandler; private Handler mHandler;
@ -56,6 +60,11 @@ public class FFmpegHandler {
mHandler.obtainMessage(MSG_BEGIN).sendToTarget(); mHandler.obtainMessage(MSG_BEGIN).sendToTarget();
} }
@Override
public void onMsg(@NotNull String msg) {
mHandler.obtainMessage(MSG_INFO, msg).sendToTarget();
}
@Override @Override
public void onProgress(int progress, int duration) { public void onProgress(int progress, int duration) {
mHandler.obtainMessage(MSG_PROGRESS, progress, duration).sendToTarget(); mHandler.obtainMessage(MSG_PROGRESS, progress, duration).sendToTarget();
@ -97,6 +106,11 @@ public class FFmpegHandler {
mHandler.obtainMessage(MSG_BEGIN).sendToTarget(); mHandler.obtainMessage(MSG_BEGIN).sendToTarget();
} }
@Override
public void onMsg(@NotNull String msg) {
}
@Override @Override
public void onProgress(int progress, int duration) { public void onProgress(int progress, int duration) {
mHandler.obtainMessage(MSG_PROGRESS, progress, duration).sendToTarget(); mHandler.obtainMessage(MSG_PROGRESS, progress, duration).sendToTarget();
@ -130,6 +144,11 @@ public class FFmpegHandler {
mHandler.obtainMessage(MSG_BEGIN).sendToTarget(); mHandler.obtainMessage(MSG_BEGIN).sendToTarget();
} }
@Override
public void onMsg(@NotNull String msg) {
}
@Override @Override
public void onProgress(int progress, int duration) { public void onProgress(int progress, int duration) {

@ -6,6 +6,7 @@ package com.frank.ffmpeg.listener
*/ */
interface OnHandleListener { interface OnHandleListener {
fun onBegin() fun onBegin()
fun onMsg(msg: String)
fun onProgress(progress: Int, duration: Int) fun onProgress(progress: Int, duration: Int)
fun onEnd(resultCode: Int, resultMsg: String) fun onEnd(resultCode: Int, resultMsg: String)
} }

Loading…
Cancel
Save