File path for Windows standalone build

Hey guys!

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.

So my XML URL looks like this:

"Assets\Videos\Cutscenes\Intro_1.mp4"

And in my Video class I do this:

string path = Path.GetDirectoryName(Application.dataPath);
        video.url = Path.Combine(path, VID_XML_URL);

This works great in the editor! I just need it to work in stand alone as well.

As always, thank you for any input or suggestions guys!

You probably want to store your videos in StreamingAssets instead:

I did come across this but did not like the idea of having the assets easily accessible for the end user. Would there be a way to hide them as well?

Thanks!

Put them in an asset bundle. Otherwise, no.

Ah! so there is no way to just access the videos that are already being packaged from the assets directory via some other path that I am not aware of?

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.

1 Like

Ah alright!

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.

This is my XML url:

"Videos/Cutscenes/intro_1.mp4"

This is the related part of my PlayVideo()

string path = Application.dataPath + "/Resources";
        string completePath = Path.Combine(path, VID_XML_URL);
        video.clip = Resources.Load(completePath, typeof(VideoClip)) as VideoClip;
        video.url = completePath;

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”, …).

https://docs.unity3d.com/ScriptReference/Resources.Load.html

The “Resources” asset does not exist as “actual” file on the OS file-system in a build. That’s where StreamingAssets comes into play.

Also notice that Unity Technologies recommends to avoid the Resources folder:
https://unity3d.com/learn/tutorials/temas/best-practices/resources-folder

1 Like

Beautiful!

I was able to get it working perfectly with this code in Editor and Standalone!

string concatPath = VID_XML_URL.Replace(".mp4", string.Empty);
        video.clip = Resources.Load(concatPath, typeof(VideoClip)) as VideoClip;

Thanks guys!

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?

No they do. Put the video in the build without loading it via resources to determine if it’s an issue with the video or not

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. :frowning: 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! :smile:

1 Like