callback error msg to java

pull/190/head
xufuji456 3 years ago
parent 4708e1d422
commit 8af9adf6e8
  1. 6
      app/src/main/cpp/ffmpeg_cmd.c
  2. 17
      app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java

@ -11,6 +11,7 @@
JNIEnv *ff_env;
jclass ff_class;
jmethodID ff_method;
jmethodID msg_method;
void log_callback(void*, int, const char*, va_list);
@ -18,6 +19,7 @@ void init(JNIEnv *env) {
ff_env = env;
ff_class = (*env)->FindClass(env, "com/frank/ffmpeg/FFmpegCmd");
ff_method = (*env)->GetStaticMethodID(env, ff_class, "onProgressCallback", "(III)V");
msg_method = (*env)->GetStaticMethodID(env, ff_class, "onMsgCallback", "(Ljava/lang/String;)V");
}
FFMPEG_FUNC(jint, handle, jobjectArray commands) {
@ -62,6 +64,10 @@ void log_callback(void* ptr, int level, const char* format, va_list args) {
break;
case AV_LOG_ERROR:
ALOGE(FFMPEG_TAG, format, args);
if (ff_env && msg_method) {
jstring jstr = (*ff_env)->NewStringUTF(ff_env, format);
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, msg_method, jstr);
}
break;
default:
ALOGI(FFMPEG_TAG, format, args);

@ -23,6 +23,8 @@ public class FFmpegCmd {
System.loadLibrary("media-handle");
}
private final static String TAG = FFmpegCmd.class.getSimpleName();
private final static int RESULT_SUCCESS = 1;
private final static int RESULT_ERROR = 0;
@ -58,7 +60,7 @@ public class FFmpegCmd {
//call JNI interface to execute FFmpeg cmd
int result = handle(commands);
if (onHandleListener != null) {
onHandleListener.onEnd(result, null);
onHandleListener.onEnd(result, "");
}
mProgressListener = null;
}
@ -88,10 +90,10 @@ public class FFmpegCmd {
for (String[] command : commands) {
result = handle(command);
count ++;
Log.i("FFmpegCmd", count + " result=" + result);
Log.i(TAG, count + " result=" + result);
}
if (onHandleListener != null) {
onHandleListener.onEnd(result, null);
onHandleListener.onEnd(result, "");
}
mProgressListener = null;
}
@ -158,7 +160,7 @@ public class FFmpegCmd {
private native static String handleProbe(String[] commands);
public static void onProgressCallback(int position, int duration, @FFmpegState int state) {
Log.e("FFmpegCmd", "onProgress position=" + position
Log.e(TAG, "onProgress position=" + position
+ "--duration=" + duration + "--state=" + state);
if (position > duration && duration > 0) {
return;
@ -174,4 +176,11 @@ public class FFmpegCmd {
}
}
}
public static void onMsgCallback(String msg) {
if (msg != null && !msg.isEmpty()) {
Log.e(TAG, "from native msg=" + msg);
}
}
}
Loading…
Cancel
Save