如何在上传过程中分割的android中播放视频?

时间:2019-03-13 17:02:11

标签: android firebase video-streaming firebase-storage android-videoview

由于Firebase存储不允许缓冲视频(我的意思是它不允许像youtube一样下载视频),因此在上传期间,我使用以下代码将视频切成较小的部分。现在,我想下载第一部分并在播放第一部分的同时播放,我想下载第二部分并在第一部分完全播放后立即播放,依此类推。谁能帮助我做到这一点?

public static List<File> splitFile(File f) throws IOException {
    int partCounter = 1;
    List<File> result = new ArrayList<>();
    int sizeOfFiles = 1024 * 1024;// 1MB
    byte[] buffer = new byte[sizeOfFiles]; // create a buffer of bytes sized as the one chunk size

    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
    String name = f.getName();

    int tmp = 0;
    while ((tmp = bis.read(buffer)) > 0) {
        File newFile = new File(f.getParent(), name + "." + String.format("%03d", partCounter++)); // naming files as <inputFileName>.001, <inputFileName>.002, ...
        FileOutputStream out = new FileOutputStream(newFile);
        out.write(buffer, 0, tmp);//tmp is chunk size. Need it for the last chunk, which could be less then 1 mb.
        result.add(newFile);
    }
    return result;
}

0 个答案:

没有答案