I am having an issue with my Video Player videos. At first I thought it might be an issue with transcoding or codecs since I found a bunch of people saying that was their issue but I think it might be something really dumb like the actual file path of the stand alone build…
So I am using the Video Player with its URL since I plan to have my game hosted online and was going to feed videos directly from my server. For testing stand alone however when I hit a video in game, it just shows me a black screen and never plays. I believe I am just simply not getting the correct path.
So currently my video URLs are being loaded in via XML to my Video Player then I combine that with the path of the game and it works perfectly in the editor, when I play the standalone nothing happens. I am pretty new to file pathing with Unity but I think that is the issue.
The directories don’t exist in the built executable. Unity crawls your assets, scoops up everything that is used somewhere, and builds a data file(s) out of those assets.
If you want to load stuff from a string-based path and don’t want to use asset bundles then you can put stuff in a Resources folder and load that way. Purportedly not great for large files (like music tracks) but it’s another tool at your disposal otherwise. All assets in Resources are built with the executable regardless of whether or not they are actually used anywhere.
So I created a resources directory and moved all of my videos to there. It works in the editor but not stand alone still. I think I am just missing something fundamentally. It is tricky because the VideoPlayer’s VideoClip needs its own URL for the video file.
Resources.Load requires the path to be relative to the Resources folder.
If you want to load “Assets/Resources/foo/bar.txt”, you’d use Resources.Load(“foo/bar”, …).
Okay so I have this working great in Editor and Standalone… but when I do a WebGL build I get the black screen of death again whenever a video should be playing. I added the XML to the resources DIR as well and am loading that now which contains the video paths. Could it be a transcoding/codec issue? I did a debug build and when I hit a black screen I did not get any errors.
Neither of these make mention of WebGL builds. I converted all of my videos to .webm and they still run great in Editor and Standalone but no videos play in my WebGL build sadly. Do Resources just not exist in WebGL builds?
Ah okay! So I found a solution for now but not sure if it is the best!
Basically for the Editor and Standalone I am still using a Resources directory which only contains videos. Then for WebGL I have a StreamingAssets dir that contains the same videos. I have a little script that excludes StreamingAssets from Standalone builds and includes it for WebGL builds. Then in my video code if the application is running in WebGL player I take the StreamingAsset videos if it is not, I take the resources videos! And this works! Without any modification to transcoding, file extension etc etc!
Not sure if this is the best way but it works for now! The final game will be on Steam and likely use the Resources directory because I don’t want people stepping into the game folders and stealing our videos. But for the web demo that I plan to release in a few days it seems like using StreamingAssets is fine since I don’t think it would be easy for the average player to access these videos from their browser! But I could be wrong!
TL;DR - Standalone game uses Resource based videos. WebGL game uses StreamingAssets based videos. Everything works!