convert Video To Bytes - Android Media

Android examples for Media:Video

Description

convert Video To Bytes

Demo Code


//package com.java2s;

import android.content.Context;

import android.net.Uri;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    public static byte[] convertVideoToBytes(Context context, Uri uri) {
        byte[] videoBytes = null;
        try {//from w  w  w. ja v  a2s  . co  m
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            //            FileInputStream fis = new FileInputStream(new File(getRealPathFromURI(context, uri)));
            FileInputStream fis = new FileInputStream(new File(
                    String.valueOf(uri)));
            byte[] buf = new byte[1024];
            int n;
            while (-1 != (n = fis.read(buf)))
                baos.write(buf, 0, n);

            videoBytes = baos.toByteArray();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return videoBytes;
    }
}

Related Tutorials