How to Play a Video in Unity WebGL (Simple)

How to Play a Video in Unity WebGL (Simple)

Max O'Didily

1 год назад

9,190 Просмотров

How to Play a Video in Unity WebGL (Simple)

Greetings, today we are here with another Unity tutorial. We shall be looking at how to play a video in a Unity WebGL game/project. Unlike with other platforms, we can't simply make a video clip and drag and drop it into a video player component. We have to do a bit more.

Unlike with other tutorials out there, our video files will be included in our WebGL game. We will be using the streaming assets folder to store our mp4 video files.

The Streaming Assets folder in Unity is a special folder that you can use to store files that you want your game or app to access while it's running. These files can be things like images, sounds, videos, or text files.

Unity doesn't touch or modify the files in this folder, so they stay exactly the same as you put them. This is important because it means your game or app can always find and use them, no matter what platform it's running on (like PC, mobile, web browser or console).

Think of the Streaming Assets folder like a storage box for your game that's always with it, so you can easily get to the stuff inside whenever you need it.

We then create a script to load the video from the streaming assets folder and pass it to the video player component.

After that, we create a render texture and a video material. We place the object where we want out video displayed and attatch the render texture to the video player component. We also attatch the render texture to the video material.

That is all that is needed to play a video in a Unity WebGL project. I also quickly show how to host a webgl game locally to make it easy to test your games.

In this tutorial, your video files are not hosted on another website like Github, Amazon AWS or YouTube. They are contained in your game's streaming assets folder.

Thanks for watching this Unity video on how to play a video in WebGL.

Subscribe to keep notified when I upload: https://tinyurl.com/SubMaxODidily

How to Play a Video in Unity WebGL (Simple)

Тэги:

#How_to_Play_a_Video_in_Unity_WebGL #play_video_in_Webgl #Play_Video_in_Unity_WebGL #How_to_play_a_video_in_Unity_WebGL #Video_in_WebGL_on_Unity #Adding_Video_to_Unity_WebGL #Video_Player_on_WebGL #Videos_don't_play_in_WebGL #how_to_play_videos_in_webgl #How_do_I_play_a_video_in_WebGL_Unity #Unity_webgl_video_player #play_video_unity_webgl #unity_webgl_play_video #show_video_unity_webgl #play_video_from_url_unity #unity_play_video_from_url #C#_play_video_webgl #C#_video_webgl
Ссылки и html тэги не поддерживаются


Комментарии:

Nadia Marzuki
Nadia Marzuki - 12.10.2023 12:44

Hey, im getting VideoPlayer does not contain definition of 'url'. :( following exactly as ur script. using 2022.3.10f1

Ответить
Huimin Loi
Huimin Loi - 22.09.2023 12:52

I get this error when trying to access the video player from my phone. NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. Everything works fine when viewing from my pc. any idea why i'm getting this error?

Ответить
Luigi Nicastro
Luigi Nicastro - 10.09.2023 22:09

Odd I get this error : "VideoPlayer cannot play url : C:/Users/Colt/Documents/GitHub/TheContemporaryHub/TheContemporaryHub/Assets/StreamingAssets"

but when I check the debug it does call the video location properly. Any ideas?

Ответить
kam o
kam o - 07.08.2023 19:29

excellent, works perfect, thanks!, by the way, in my case works in my unity 2022 version, in 2019 it wasn't .

Ответить
Ramiro Esposito
Ramiro Esposito - 29.07.2023 01:23

hey max! Nice video. i have a spritesheet map animation but its to heavy because the resolution is too high. I try to low the resolution but the spritesheet is still really heavy. I was thinking in render a video and use that instead with this approach you show. Do you think is a good idea or do you know a better way to do ir?

Ответить
KPrograM
KPrograM - 24.07.2023 16:32

The video you presented is to do it with a video that has already been prepared, and what I want is to print a video that shares the real-time screen on the UI. Is there a way?

Ответить
KPrograM
KPrograM - 24.07.2023 12:21

I'm sharing a screen on the web and I want to print this out on Unity 2D UI. Please teach me the way.

Ответить
philipino
philipino - 21.07.2023 21:16

this worked!!!! oh my!!! unity dont make it clear how to do this. no one has made a clear guide where we can just play the video file from our project. i contemplated spending £150 for that plugin but then I find your video. you saved me so much money, thanks so much for making this free

Ответить
容子千
容子千 - 21.07.2023 14:28

When I try to test webgl local, I only get video's sound without picture, I dont know why😭😭😭

Ответить
杨智程
杨智程 - 19.07.2023 13:42

would you create a new for 2D game ? will this thing work in a 2D game developed in Unity

Ответить
Casey KG
Casey KG - 17.05.2023 00:14

I appreciate the video, It saves me ever having to buy an asset that costs hundreds of pounds when it only took a few lines of code. Thank You!

Ответить