2017-09-06 176 views
1

我无法为ffmpeg调用Android java库的某些方法。我想我successfuly加载库,因为我可以CONSOLE.LOG库对象:如何在Nativescript中实现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] } 

这是多远我得到了(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) 
+0

的JavaScript不是Java – Acidic

+0

如果您没有看到错误的活动,那么它是一个JNI除外,它只能在亚行logcat进行跟踪。但是,这可能会在nativescript论坛中找到更好的答案。另外,共享可以复制问题的存储库将是理想的。 – pkanev

+0

实际上,在控制台上有特定消息,JNI例外可能如您所建议的那样?我将它们包含在 –

回答

0

上根据试样的github库https://github.com/WritingMinds/ffmpeg-android-java/blob/master/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java#L80

execute方法接受字符串集合/数组作为它的第一个参数。因此,你的代码应该是这样的:

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

事实上,这是问题所在!在重新构建并且处理程序实际记录信息以及ffmpeg输出后,崩溃消失了。非常感谢你! –