Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Byte array (Byte[]) to a video (Android)

So i have uploaded my video to my amazon DataBase, and now i Want to download it and display it, here is the part of my code where i download it:

S3ObjectInputStream content = s3.getObject(
                            Constants.getVideoBucket(),
                            keyList.get(i).getKey().toString())
                            .getObjectContent();
                    byte[] bytes = IOUtils.toByteArray(content);

Now I have the byte array that has the video, but i dont know what to do next. What should i do? I want to display it on a VideoView that I have ready.

help will be much apreciated

ps: i dont want to write down the video to the sd card! (imagine a youtube video, it gisplays but it wont write to ur sd card every video you watch.!)!!!!!!!!!!!!

EDIT1: i did this with the pictures:

S3ObjectInputStream content = s3.getObject(
                            Constants.getPictureBucket(),
                            keyList.get(i).getKey().toString())
                            .getObjectContent();
                    byte[] bytes = IOUtils.toByteArray(content);
bitmap = BitmapFactory.decodeByteArray(bitmaparray.get(i), 0,
                            bitmaparray.get(i).length);             
                    imageview.setImageBitmap(bitmap); 

as you can see, i converted the byte array to bitmap and then displayed it to a imageview, could you please help me to do the same with the video one???

like image 514
luthor Avatar asked Nov 23 '25 08:11

luthor


1 Answers

You can try this with appropriate permissions.

FileOutputStream out = new FileOutputStream("sdcard path where you want to save video");
out.write(bytes);
out.close();
videoView.setVideoPath(“path to saved video“).
like image 74
Altaf Avatar answered Nov 24 '25 21:11

Altaf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!