- Home /
Play Video from Byte[]
Hello, I store my video in a MySQL database with a LONGBLOB field. With a MySqlDataReader a get my video as a Byte[]. How can I convert it in a VideoClip to play it in a VideoPlayer ? Thanks for taking the time to read this :)
I'm looking an answer for this as well. I have bytes[] which I want to load into videoClip. Please let me know, if you have an answer. Thanks.
Answer by Bunny83 · Feb 28, 2018 at 12:19 AM
In short: You can't directly use a byte array.
The VideoClip class is a transcoded asset that is supposed to be stored in your project. VideoClips can only be created in the editor by the VideoClipImporter. So you can't use a VideoClip when you want to view dynamically loaded video data at runtime.
However the VideoPlayer allows you to play a video file given either an HTTP URL or an absolute or relative file path on the target device. That means if you have your video as byte array you would need to store it in a file and let the VideoPlayer play that file.
Pretty much all of that can be directly derived from reading the documentation links i've provided.
Thank you for the answer. Let's say there is a large video file, will VideoPlayer take care of strea$$anonymous$$g/buffering it? I'm targetting mobile devices & am concerned that - if I feed the file path, videoplayer might load the whole video into memory?
Answer by dimib · Apr 28, 2020 at 08:59 PM
Unfortunately, Android Q (10) has a lot of problems when trying to access files from the emulated storage (not application data path or streaming assets path).
Also I agree with @karsnen that it is not feasible to load a video into memory and save it to dataPath or temporary cache path to just play it in Unity.