Android Phonegap视频捕获崩溃
我制作了一个相对简单的phonegap应用程序,能够捕获图像和视频并上传到服务器 图像工作正常,但当我调用以捕获视频时,会显示摄像头UI,当我接受视频时,应用程序会在logcat中崩溃,并出现以下错误:Android Phonegap视频捕获崩溃,android,video,cordova,phonegap-plugins,Android,Video,Cordova,Phonegap Plugins,我制作了一个相对简单的phonegap应用程序,能够捕获图像和视频并上传到服务器 图像工作正常,但当我调用以捕获视频时,会显示摄像头UI,当我接受视频时,应用程序会在logcat中崩溃,并出现以下错误: java.lang.RuntimeException: Failure delivering result ResultInfo(who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/me
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
我使用的是phonegap 3.0.0,我已经通过命令行界面安装了正确的插件,我的AndroidManifest很好
我使用的是phonegap API中的演示代码,因此问题也不存在。此问题的解决方法是编辑[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();
到下面的代码
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();
这对我们来说是有效的,希望它很快会被正确修复。我认为更好的解决方案是实际阻止使用UI线程,而不是禁用线程检查 我是这样解决的:
private JSONObject createMediaFile(final Uri data) {
Future<JSONObject> result = cordova.getThreadPool().submit(new Callable<JSONObject>()
{
@Override
public JSONObject call() throws Exception
{
File fp = webView.getResourceApi().mapUriToFile(data);
JSONObject obj = new JSONObject();
try {
// File properties
obj.put("name", fp.getName());
obj.put("fullPath", fp.toURI().toString());
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
// is stored in the audio or video content store.
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
if (data.toString().contains("/audio/")) {
obj.put("type", AUDIO_3GPP);
} else {
obj.put("type", VIDEO_3GPP);
}
} else {
obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova));
}
obj.put("lastModifiedDate", fp.lastModified());
obj.put("size", fp.length());
} catch (JSONException e) {
// this will never happen
e.printStackTrace();
}
return obj;
}
});
try
{
return result.get();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
return null;
私有JSONObject createMediaFile(最终Uri数据){
Future result=cordova.getThreadPool().submit(new Callable())
{
@凌驾
公共JSONObject调用()引发异常
{
文件fp=webView.getResourceApi().mapUriToFile(数据);
JSONObject obj=新的JSONObject();
试一试{
//文件属性
obj.put(“name”,fp.getName());
obj.put(“完整路径”,fp.toURI().toString());
//因为MimeTypeMap.getMimeTypeFromExtension()所有.3gpp文件存在问题
//被报告为video/3gpp。我正在对URI进行黑客检查,看看它是否
//存储在音频或视频内容存储中。
if(fp.getAbsoluteFile().toString().endsWith(“.3gp”)| | fp.getAbsoluteFile().toString().endsWith(“.3gpp”)){
if(data.toString()包含(“/audio/”){
obj.put(“类型”,音频3GPP);
}否则{
obj.put(“类型”,视频3GPP);
}
}否则{
put(“type”,FileHelper.getMimeType(Uri.fromFile(fp),cordova));
}
对象put(“lastModifiedDate”,fp.lastModified());
对象放置(“大小”,fp.length());
}捕获(JSONException e){
//这永远不会发生
e、 printStackTrace();
}
返回obj;
}
});
尝试
{
返回result.get();
}
捕捉(中断异常e)
{
e、 printStackTrace();
}
捕获(执行例外)
{
e、 printStackTrace();
}
返回null;
我将默认方法包装在一个可调用的内部类中。现在它在另一个线程中执行。同样的问题。直到最近它还运行得很好。我认为新的phonegap更新有问题。很高兴听到,我觉得我疯了。提交了这个问题。你能粘贴你正在使用的代码或指出哪个exa吗从您使用的文档中复制示例?我刚刚尝试过,无法再复制错误,因此我想知道您是否从文档中复制了一个坏示例…//捕获回调var capturesucture=function(mediaFiles){var I,path,len;for(I=0,len=mediaFiles.length;I