cameraKit-android输出视频

时间:2017-07-05 03:44:12

标签: android android-camera

有没有人使用gogopop的CameraKit-Android?我的问题是我设置了视频的监听器,但输出文件是null。有谁知道如何解决它?

这是我的代码:

        cameraView.getCamera().setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_720P);
        cameraView.getCamera().startRecordingVideo();
        cameraView.getCamera().setCameraListener(new CameraListener() {
            @Override
            public void onVideoTaken(final File video) {
                super.onVideoTaken(video);
            /*    new Thread(new Runnable() {
                    @Override
                    public void run() {
                        final byte[] videoBytes = FileUtils.File2byte(video.getAbsolutePath());
                        if (!isExit) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    saveFile(videoBytes);
                                }
                            }).start();
                        }
                        isExit = false;
                    }
                }).start();*/
            }
        });

我已经习惯制作一个新文件来保存mp4,但是当我录制超过一分钟的视频时,该应用就是OOM。有人可以帮帮我吗?感谢。

2 个答案:

答案 0 :(得分:0)

我解决了这个问题。这不是cameraKit-android issuse。这是Android的问题,它有两点:

  1. 文件已退出,但您没有通知系统。所以你应该:

          cameraView.getCamera().setCameraListener(new CameraListener() {
            @Override
            public void onVideoTaken(final File video) {
                super.onVideoTaken(video);
                //notify system refresh
                Uri localUri = Uri.fromFile(video);
                Intent localIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, localUri);
                sendBroadcast(localIntent);
    
  2. 尝试这个家伙的想法,我用它来保存susscess:

    String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/milai/";
    
    File appDir = new File(path);
    
    if (!appDir.exists()) {
        appDir.mkdir();
    }
    mVideoFile = new File(mPreview.getView().getContext().getExternalFilesDir(null), getPicTime()+".mp4");
    String myFile = path+getPicTime()+".mp4";
    mMediaRecorder.setOutputFile(myFile);
    
  3. 它看起来一样,但我不知道为什么会成功。如果eveybody有其他问题,可以问我。我会尽力帮助你。

答案 1 :(得分:0)

我对这个问题的解决方案;

  public static void saveVideoToFile( File video) {
        try {

            File newfile;

            FileInputStream fileInputStream = new FileInputStream(video);
            File filepath = Environment.getExternalStorageDirectory();
            File dir = new File(filepath.getAbsolutePath() + "/" + "Your File Name" + "/");
            if (!dir.exists()) {
                dir.mkdirs();
            }

            newfile = new File(dir, "save_" + System.currentTimeMillis() + ".mp4");

            if (newfile.exists()) newfile.delete();
            OutputStream out = new FileOutputStream(newfile);
            // Copy the bits from instream to outstream
            byte[] buf = new byte[1024];
            int len;

            while ((len = fileInputStream.read(buf)) > 0) {
                out.write(buf, 0, len);
            }

            fileInputStream.close();
            out.close();

            MyLog.log("Copy file successful.");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }