如何保存视频?

时间:2017-04-30 11:45:06

标签: android

如何将视频从我的原始文件夹保存到SD卡android,我使用此代码,但商店屏幕中的视频是黑色的,无法播放

public boolean onTouch(View v, MotionEvent event) {

    boolean success = false;

    // make the directory
    File vidDir = new File(android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) + File.separator + "MY VIDEO");
    vidDir.mkdirs();
    // create unique identifier
    Random generator = new Random();
    int n = 100;
    n = generator.nextInt(n);
    // create file name
    String videoName = "Video_" + n + ".mp4";
    File fileVideo = new File(vidDir.getAbsolutePath(), videoName);

    try {
        fileVideo.createNewFile();
        success = true;
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (success) {
        Toast.makeText(getApplicationContext(), "Video saved!",
            Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getApplicationContext(),
            "Error during video saving", Toast.LENGTH_LONG).show();
    }

    return true;
}

0 个答案:

没有答案