Phonegap视频捕获崩溃

Ric*_*ard 4 video android phonegap-plugins cordova

我制作了一个相对简单的phonegap应用程序,能够捕获图像和视频并将它们上传到服务器.

图像工作正常,但是当我调用捕获视频时,会出现相机UI,当我接受视频时,应用程序在logcat中出现此错误:

java.lang.RuntimeException: Failure delivering result ResultInfo(who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/media/46536 }} to activity {myApp.test.app}: java.lang.IllegalStateException:Do not perform IO operations on the UI thread. Use CordovaInterface.getThreadPool() instead
Run Code Online (Sandbox Code Playgroud)

我正在使用phonegap 3.0.0,我已经通过命令行界面安装了正确的插件,我的AndroidManifest很好.

我正在使用来自phonegap API的演示代码,所以问题也不存在.

小智 11

此问题的解决方法是编辑[yourApp]\plugins\org.apache.cordova.media-capture\src\android\Capture.java

从第377行开始,更改此代码

private JSONObject createMediaFile(Uri data) {
    File fp = webView.getResourceApi().mapUriToFile(data);
    JSONObject obj = new JSONObject();
Run Code Online (Sandbox Code Playgroud)

到以下代码

private JSONObject createMediaFile(Uri data) {
    // is thread checking enabled?
    boolean thC = webView.getResourceApi().isThreadCheckingEnabled();       
    // set thread checking to disabled (this works around mapUriToFile failing with IllegalStateException: Do not perform IO operations on the UI thread.
    webView.getResourceApi().setThreadCheckingEnabled(false);       
    File fp = webView.getResourceApi().mapUriToFile(data);
    // set thread checking back to whatever it was before the call above.
    webView.getResourceApi().setThreadCheckingEnabled(thC);
    JSONObject obj = new JSONObject();
Run Code Online (Sandbox Code Playgroud)

这对我们有用,希望很快就会得到妥善解决.

  • 为我工作.确保更改platform目录中的org/apache/cordova/mediacapture内的java文件以及plugins目录中的java文件. (3认同)