- Home /
Dynamicaly load a video on a GameObject
Hello,
I searched for a good while but all my attempts resulted in failures until now. I need to write a script able to load and display on a GameObject a video from its very link. My point is to make sure by only writing down the disk link of the video on a text file, the referenced video will be loaded from a script.
My expectations went short when I couldn't seem to manage to find proper "Resource.Load" like I did for loading textures from their link.
Anybody can land me a hand here ?
Thank you.
Edit: Idealy, I'd like to load a videoclip from its link.
Answer by Legend_Bacon · Nov 16, 2017 at 05:47 PM
Hello there,
If you have a (relatively) recent version of Unity, you might want to try their Video Player. It's pretty simple, and seems to work great. I use it to have a video rendered on a plane.
In terms of code, you can play the video like this:
public void PlayVideo(string videoName)
{
VideoClip clip = Resources.Load<VideoClip>(videoName) as VideoClip;
vp_VideoPlayerRef.clip = clip;
vp_VideoPlayerRef.Play();
}
There are heavy restrictions on which formats it supports though, so I'd recommend reading the above link in details. But if you follow all their rules, you can just load a video from Resources and play it.
Hope that helps!
~LegendBacon
Hi, sorry for the late reply but I couldn't afford to spend too much time on the matter anymore yesterday. The problem was actualy a corruption of my video in the first place, so a simple Resources.Load() of VideoClip was enough, since I have a custom videoplayer for taking charge of VideoClip elements.
Thank you for the tip, though, this will definitively help on my future work.
Have an excellent day.
Hi, I need to get video clip which is placed under Resources/subfolder, these subfolder names and videos will be dynamic, user will place those. In Editor its working fine with Resources. Load property, while we taking build - if we take build with Resources folder with all contents, it will reflect. But the changes in folder and files will not get reflected. Is there any other way to retrieve video clips.
Hello there,
While this should probably be a separate question of its own, I'll answer it here. You mention that you want you folder system to be dynamic, but you also say you use Resources for this. Just to clarify, the Resources folder is NOT dynamic. You can put stuff in there that you want/need your project to load with, but you can't add folders or files to it at runtime. (Not in a build, at least).
Ins$$anonymous$$d, you should probably just use Application.persistentDataPath to achieve this kind of behavior.
I hope that helps!
Cheers,
~LegendBacon
Your answer
Follow this Question
Related Questions
Resources.Load dynamic path 2 Answers
Video Player preparing too long Android 0 Answers
Display dynamic video content on the fly 0 Answers
Dynamically load AudioClip during runtime 1 Answer
non-dynamic asset load? 1 Answer