Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i play video from byte in android

I have video in my project. and for security i encrypt the video files which is working quite well. but problem is that the

 **videoView.setVideoPath("/mnt/sdcard/intro_video.3gp");** 

In this method I have to pass the file.(which is decrypted) so I am creating decrypted file on sdcard for path of file is that possible to pass bytes (which are decrypted) directly in video view. I am using Cipher for encrypt.

Here is my code for

 private void decryption()throws Exception {
    // TODO Auto-generated method stub
    String filePath2 = path + "en/encVideo";

    String filePath3 = path + "de/decVideo";

    File decfile = new File(filePath3);


    if(!decfile.exists())
        decfile.createNewFile();

    File outfile = new File(filePath2);
    int read;

    FileInputStream encfis = new FileInputStream(outfile);
    Cipher decipher = Cipher.getInstance("AES");

    decipher.init(Cipher.DECRYPT_MODE, skey);
    FileOutputStream decfos = new FileOutputStream(decfile);
    CipherOutputStream cos = new CipherOutputStream(decfos,decipher);   

    while((read=encfis.read()) != -1)
    {

        cos.write(read);
        cos.flush();
    }
    cos.close(); 
}
like image 658
Youddh Avatar asked Jun 09 '12 07:06

Youddh


2 Answers

If streaming the video to a VideoView without an intermediary file to store the decrypted version is what you are looking for, then the answer is Yes you can do it. You need two main components: a streaming server such as a local http instance and CipherInputStream.

like image 161
libeasy Avatar answered Oct 26 '22 18:10

libeasy


I doubt you can do it. Since you are using VideoView, it would require specific headers and tail ends that suggest which format and how it is encoded etc. If you can figure out that I still doubt it can take raw file. Your best bet would be to create random file names while saving and passing that to the player.

like image 1
Oasa Avatar answered Oct 26 '22 17:10

Oasa