Javascript 如何在Nativescript中实现Java方法?

Javascript 如何在Nativescript中实现Java方法?,javascript,java,android,ffmpeg,nativescript,Javascript,Java,Android,Ffmpeg,Nativescript,我在为ffmpeg调用Android java库的某些方法时遇到问题。我想我成功加载了库,因为我可以控制台。记录库对象: JS: BuildConfig -> function () { [native code] } JS: ExecuteBinaryResponseHandler -> function () { [native code] } JS: FFmpeg -> function () { [native code] } JS: FFmpegExecuteResp

我在为ffmpeg调用Android java库的某些方法时遇到问题。我想我成功加载了库,因为我可以控制台。记录库对象:

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] }

这就是我走了多远():

/[…]
var MyCustomLoadBinaryResponseHandler=
com.github.hiteshondhi88.libffmpeg
.LoadBinaryResponseHandler.extend({
onStart:function(){
log('开始加载ffmpeg');
},
onFailure:function(){
log('加载ffmpeg失败');
},
onSuccess:function(){
log('已成功加载ffmpeg');
},
onFinish:function(){
log('Finished loading ffmpeg');
}
});
console.dir(MyCustomLoadBinaryResponseHandler);
//^这将记录以下内容
//~JS:==dump():转储成员===
//~JS:“()函数(){[本机代码]}”
//~JS:==dump():转储函数和属性名称===
//~JS:extend()
//~JS:null()
//~JS:==dump():已完成===
var context=app.android.context;
var ffmpeg=
com.github.hitehsondhi88.libffmpeg.FFmpeg.getInstance(上下文);
console.dir(ffmpeg);
//^这将记录以下内容
//~JS:==dump():转储成员===
//~JS:{
//~JS:“构造函数”:“构造函数()函数(){[本机代码]
//}"
//~JS:}
//~JS:==dump():转储函数和属性名称===
//~JS:constructor()
//~JS:concatenate()
//~JS:execute()
//~JS:getDeviceFmPegVersion()
//~JS:getLibraryFFmpegVersion()
//~JS:isFFmpegCommandRunning()
//~JS:killrunningprocesss()
//~JS:loadBinary()
//~JS:setTimeout()
//~JS:()
//~JS:clone()
//~JS:equals()
//~JS:finalize()
//~JS:getClass()
//~JS:hashCode()
//~JS:notify()
//~JS:notifyAll()
//~JS:toString()
//~JS:等等()
//~JS:==dump():已完成===
ffmpeg.loadBinary(
新的MyCustomLoadBinaryResponseHandler()
);
var MyCustomExecuteBinaryResponseHandler=
com.github.hiteshondhi88.libffmpeg
.ExecuteBinaryResponseHandler.extend({
onStart:function(){
log('开始运行ffmpeg');
},
onProgress:函数(此消息){
log('ffmpeg running');
console.log(thisMessage);
},
onFailure:函数(此消息){
log('运行ffmpeg失败');
console.log(thisMessage);
},
onSuccess:函数(此消息){
log('成功运行ffmpeg');
console.log(thisMessage);
},
onFinish:function(){
log('Finished running ffmpeg');
}
});
//这就是它崩溃的地方
ffmpeg.execute('-version',新建

MyCustomExecuteBinaryResponseHandler())

execute
方法接受字符串集合/数组作为其第一个参数。因此,您的代码应该如下所示:

ffmpeg.execute(['-version'], new MyCustomExecuteBinaryResponseHandler());

根据示例github存储库

execute
方法接受字符串集合/数组作为其第一个参数。因此,您的代码应该如下所示:

ffmpeg.execute(['-version'], new MyCustomExecuteBinaryResponseHandler());

如果您没有看到错误活动,那么它是一个JNI异常,只能在ADB Logcat中跟踪。不过,这可能会在nativescript论坛中找到更好的答案。此外,共享一个可以重现问题的存储库是理想的。实际上,具体来说,控制台上有消息,JNI异常可能如您所建议的那样?我将把它们包括在我最近没有使用过的问题中,但是您应该能够为您的库生成类型定义。我发现在NativeScript中使用本机库时,使用类型定义很有帮助。如果您没有看到错误活动,那么这是一个JNI异常,只能在ADB Logcat中跟踪。不过,这可能会在nativescript论坛中找到更好的答案。此外,共享一个可以重现问题的存储库是理想的。实际上,具体来说,控制台上有消息,JNI异常可能如您所建议的那样?我将把它们包括在我最近没有使用过的问题中,但是您应该能够为您的库生成类型定义。我发现在NativeScript中使用本机库时,使用类型定义很有帮助。事实上,这就是问题所在!再次构建之后崩溃消失了,处理程序实际上记录了信息以及ffmpeg输出。非常感谢你!事实上,这就是问题所在!再次构建之后崩溃消失了,处理程序实际上记录了信息以及ffmpeg输出。非常感谢你!