【发布时间】:2018-02-14 15:18:15
【问题描述】:
我在为 ffmpeg 调用 Android java 库的某些方法时遇到问题。我想我成功加载了库,因为我可以 console.log 库对象:
JS: BuildConfig -> function () { [native code] }
JS: ExecuteBinaryResponseHandler -> function () { [native code] }
JS: FFmpeg -> function () { [native code] }
JS: FFmpegExecuteResponseHandler -> function () { [native code] }
JS: FFmpegLoadBinaryResponseHandler -> function () { [native code] }
JS: LoadBinaryResponseHandler -> function () { [native code] }
This is the code I want to "translate" (under Usage)
这是我走了多远(using this nativescript guide):
// [...]
var MyCustomLoadBinaryResponseHandler =
com.github.hiteshsondhi88.libffmpeg
.LoadBinaryResponseHandler.extend({
onStart: function() {
console.log('Started loading ffmpeg');
},
onFailure: function() {
console.log('Failed loading ffmpeg');
},
onSuccess: function() {
console.log('Successfully loaded ffmpeg');
},
onFinish: function() {
console.log('Finished loading ffmpeg');
}
});
console.dir(MyCustomLoadBinaryResponseHandler);
//^ this logs the following
//~ JS: === dump(): dumping members ===
//~ JS: "()function () { [native code] }"
//~ JS: === dump(): dumping function and properties names ===
//~ JS: extend()
//~ JS: null()
//~ JS: === dump(): finished ===
var context = app.android.context;
var ffmpeg =
com.github.hiteshsondhi88.libffmpeg.FFmpeg.getInstance(context);
console.dir(ffmpeg);
//^ this logs the following
//~ JS: === dump(): dumping members ===
//~ JS: {
//~ JS: "constructor": "constructor()function () { [native code]
//}"
//~ JS: }
//~ JS: === dump(): dumping function and properties names ===
//~ JS: constructor()
//~ JS: concatenate()
//~ JS: execute()
//~ JS: getDeviceFFmpegVersion()
//~ JS: getLibraryFFmpegVersion()
//~ JS: isFFmpegCommandRunning()
//~ JS: killRunningProcesses()
//~ JS: loadBinary()
//~ JS: setTimeout()
//~ JS: <init>()
//~ JS: clone()
//~ JS: equals()
//~ JS: finalize()
//~ JS: getClass()
//~ JS: hashCode()
//~ JS: notify()
//~ JS: notifyAll()
//~ JS: toString()
//~ JS: wait()
//~ JS: === dump(): finished ===
ffmpeg.loadBinary(
new MyCustomLoadBinaryResponseHandler()
);
var MyCustomExecuteBinaryResponseHandler =
com.github.hiteshsondhi88.libffmpeg
.ExecuteBinaryResponseHandler.extend({
onStart: function() {
console.log('Started running ffmpeg');
},
onProgress: function(thisMessage) {
console.log(' ffmpeg running');
console.log(thisMessage);
},
onFailure: function(thisMessage) {
console.log('Failed running ffmpeg');
console.log(thisMessage);
},
onSuccess: function(thisMessage) {
console.log('Successfully run ffmpeg');
console.log(thisMessage);
},
onFinish: function() {
console.log('Finished running ffmpeg');
}
});
//this is where it crashes
ffmpeg.execute('-version', new
MyCustomExecuteBinaryResponseHandler());
不幸的是,整个应用程序崩溃,没有错误消息,除非我有更多关于正在发生的事情的信息,否则我无法继续。我是否以错误的方式实施这些方法?你建议我如何继续?
编辑:这些是控制台上的最后日志
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] from java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[])
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethodNative(Native method)
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethod(Runtime.java:912)
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethod(Runtime.java:896)
09-06 11:22:58.884 31522 31522 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethod(Runtime.java:888)
09-06 11:22:59.021 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodNative(Native method)
09-06 11:22:59.021 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
09-06 11:22:59.021 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
09-06 11:22:59.021 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:912)
09-06 11:22:59.021 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:896)
09-06 11:22:59.021 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:888)
09-06 11:22:59.022 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodNative(Native method)
09-06 11:22:59.022 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
09-06 11:22:59.022 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
09-06 11:22:59.022 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:912)
09-06 11:22:59.022 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:896)
09-06 11:22:59.022 31522 31522 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:888)
【问题讨论】:
-
如果您没有看到错误活动,那么它是一个 JNI 异常,只能在 ADB Logcat 中进行跟踪。但是,这可能会在 nativescript 论坛中找到更好的答案。此外,共享一个可以重现问题的存储库将是理想的。
-
实际上控制台上有消息,JNI异常可能如您所建议的那样?我会将它们包括在问题中
-
我最近没用过这个,但是你应该可以为你的库生成类型定义。我发现在 NativeScript github.com/NativeScript/android-dts-generator 中使用原生库时,类型定义很有帮助
标签: javascript java android ffmpeg nativescript