FileNotFoundException异常时,试图上传从Android应用程序记录的视频服务器 [英] FileNotFoundException when trying to upload a recorded video to server from Android app

查看:212
本文介绍了FileNotFoundException异常时,试图上传从Android应用程序记录的视频服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想录制视频,然后上传到建成后的服务器。有关code是在这里:

I'm trying to record a video and then upload it to a server upon its completion. Relevant code is here:

public void recordVideo(View view){
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    startActivityForResult(takeVideoIntent, VIDEO_RESULT);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VIDEO_RESULT){
        handleCameraVideo(data);
    }
}

private void handleCameraVideo(Intent intent) {
    Uri mVideoUri = intent.getData();
    File vidFile = new File(mVideoUri.getPath());
    RequestParams params = new RequestParams();
    try{
        params.put("video", vidFile);
    } 
    catch (FileNotFoundException e) {
        e.printStackTrace();
    }
        //finish upload here, this part isn't relevant to my question
}

问题是,在我的尝试阻止FileNotFoundException异常被抛出,而堆栈跟踪打印出来。它好像我应该得到正确的文件:我得到了大部分的$ C $的C到哪里我做从Android开发者网站上的文件的一部分,所以它应该工作 - 这使我相信这个问题是在文件vidFile =新的文件(mVideoUri.getPath()); 行。任何帮助将是AP preciated。

The problem is that in my try block a FileNotFoundException gets thrown, and the stack trace prints out. It seems as though I should be getting the right file: I got most of the code up to the part where I make the File from the Android developer site, so it should work -- which leads me to believe that the problem is at the File vidFile = new File(mVideoUri.getPath()); line. Any help would be appreciated.

推荐答案

我最终发现放在这里的另一个问题是有一些code,帮助我的:

I ended up finding another question on here that had some code that helped me out:

private String getRealPathFromURI(Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

然后在我的 handleCameraVideo 方法:

private void handleCameraVideo(Intent intent) {
    Uri mVideoUri = intent.getData();
    String data = getRealPathFromURI(mVideoUri);
    File vidFile = new File(data);
 ....

这工作,并得到了我正确的文件。

This works and gets me the right file.

这篇关于FileNotFoundException异常时,试图上传从Android应用程序记录的视频服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆