Search Unity

Video Convert byte[] to videoClip and assign it to a video player.

Discussion in 'Audio & Video' started by Deep_Ak, Mar 19, 2018.

  1. Deep_Ak

    Deep_Ak

    Joined:
    Jun 24, 2015
    Posts:
    29
    Hi guys,

    I have some images and videos stored in a server. I fetch all images and serialize the images as a list of byte arrays, and when I want to display an image I deserialize the list, take whichever byte array I need and convert it back to a sprite using
    Texture2D.LoadImage(TheByteArray[])
    I want to do the same with a video, I am able to save different videos as a byte array using
    www.bytes
    and using a BinaryFormatter to save a file at Application.persistentDataPath as a .dat file, how do I convert the byte array back to a VideoClip so I can load it onto a VideoPlayer?
     
    Last edited: Mar 19, 2018
  2. Deep_Ak

    Deep_Ak

    Joined:
    Jun 24, 2015
    Posts:
    29
    Alright got one way, it doesn't save it as a list of bytes but it saves the video as a whole in the Application.persistentDataPath using
    File.WriteAllBytes(Application.persistentDataPath + "/YourVideoName.mp4", www.bytes);
    Also, it shouldn't be a .dat file or any other random extension. It should have a .mp4 extension if that's the file you're downloading(though that's not the case with downloading an image, a .dat file or even a .banana extension works). For now, it doesn't seem like just the byte array can be converted to a VideoClip.
     
    Joits likes this.