java非法参数异常:inputFile不存在

时间:2018-10-01 03:47:41

标签: android android-intent android-file

我正在开发一个通过意图从存储中获取视频的视频。所以我正面临这个问题

问题:-

java.lang.illegalArgumentException:inputFile不存在:/ document / video:105065

代码:-

意图

    public void videotext( View v ) {
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.setType("video/*");
        startActivityForResult(i, request);
    }

关于活动结果

  @Override
    protected void onActivityResult( int requestCode, int resultCode, Intent data ) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == request) {
                uri = data.getData();
                mSurfaceView.setVideoURI(uri);
                //MediaController media1=new MediaController(this);
                media.setAnchorView(mSurfaceView);
                mSurfaceView.setMediaController(media);
                mSurfaceView.start();
                inputFile=new File(uri.getPath());
                inputFile=inputFile.getAbsoluteFile();
                VideoCompress(inputFile,OutputFile);
            }

        }
    }
    

VideoCompress是一种压缩视频的方法。

    public  void VideoCompress(File inputFile,File OutputFile)
    {

        GiraffeCompressor.create() //two implementations: mediacodec and ffmpeg,default is mediacodec
                .input(inputFile) //set video to be compressed
                .output(OutputFile) //set compressed video output
                .bitRate(2073600)//set bitrate 码率
                .resizeFactor(Float.parseFloat(String.valueOf(1.0)))//set video resize factor 分辨率缩放,默认保持原分辨率
               // .watermark("/sdcard/videoCompressor/watermarker.png")//add watermark(take a long time) 水印图片(需要长时间处理)
                .ready()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GiraffeCompressor.Result>() {
                    @Override
                    public void onCompleted() {
                        Toast.makeText(UploadVideo.this,"Compressing",Toast.LENGTH_LONG).show();

                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(UploadVideo.this,e.toString(),Toast.LENGTH_LONG).show();

                    }

                    @Override
                    public void onNext(GiraffeCompressor.Result s) {
                        Toast.makeText(UploadVideo.this,"Compressed",Toast.LENGTH_LONG).show();
                    }
                });

    }

1 个答案:

答案 0 :(得分:0)

使用此方法获取您Uri的路径:

public static String getPath(Context context,Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}

mSurfaceView.setVideoURI(data.getData());

一样使用