How to Play a Video From a URL in Unity (Works With Webgl)
Max O'Didily
How to Play a Video From a URL in Unity (Works With Webgl)
Greetings, in this unity tutorial we shall be looking at how to play a video from a url in Unity. This tutorial will work with Unity WebGL games and is a great solution to playing a video in WebGL if you don't want to use the Streaming Assets folder.
So in this Unity video we will be playing a video from a url, this url contains the video we want to play in Unity. This video will be hosted on an external website. We will be using GitHub pages but you can use other hosts.
Here is a tutorial on how to host a video on github pages for free: https://www.youtube.com/watch?v=__dIztD5FSA
This tutorial will show you how to stream a video from a website using Unity.
Now to play a video that is hosted on a website in Unity, we need to create a video player script. This script will allow us to assign the url of our video we want to play, disable play on awake and let us call the prepare video function.
The prepare function for the unity video player prepares the video for streaming, once the video is ready to be streammed, it will broadcast the prepareCompleted event. We can subscribe to this event and call the Play() function from the videoplayer to start playing the video when ready.
With the custom video player script set up, we can create a video texture and hook that videotexture up to a raw UI image and our video player component. You can use a regualr UI image if you wish but the raw UI image setup allows us to play a video in Unity WebGL.
One important thing to note, you can't use this tutorial on how to play a video from the internet with a youtube video as the url needs to for the video file itself (which would include the .mp4 or whatever at the end). YouTube doesn't expose urls for the videos themselves, so you have to host a video elsewhere. Like on GitHub pages, which is free.
But that is it for playing a video from a url in Unity that is hosted on the internet. As you can see it is simple to use the unity videoplayer to stream a video from a website.
Thanks for watching this tutorial on how to load a video from url across internet and play it on unity as 2D UI or a 3D object's texture.
If this video on how to play a video from a url in Unity that also works in unity webgl, then be sure to subscribe to keep notified when I upload.
Play video from URL Unity How to get unity videoplayer component to play video from a url How to Play a Video From a URL in Unity (Works With Webgl) ... https://www.youtube.com/watch?v=y-lr1loC5Js
14800973 Bytes