Version: 2023.2
Language : English
Audio in WebGL
Embedded resources in WebGL

Video playback in WebGL

Unity WebGLA JavaScript API that renders 2D and 3D graphics in a web browser. The Unity WebGL build option allows Unity to publish content as JavaScript programs which use HTML5 technologies and the WebGL rendering API to run Unity content in a web browser. More info
See in Glossary
supports video playback using the VideoPlayer API. This page provides information only about the video playback capabilities that WebGL supports. To learn how to use video with your Unity application, refer to the Video Player.

Video player

You can use the Video Player component to control how to time video playback relative to other interactive behaviors in WebGL. For more information, refer to the Clock management with the Video Player component.

The only exceptions are:

  • WebGL doesn’t support frame accuracy.
  • The VideoPlayer component doesn’t support synchronous playback with captureFramerate. By default, it uses the normal asynchronous playback that’s described with the Game time update mode.

Supported video playback features and formats

Unity WebGL supports the following video playback audio output modes:

Class Use
VideoAudioOutputMode.None Disables the embedded audio.
VideoAudioOutputMode.Direct Sends the embedded audio directly to the platform’s audio hardware.
VideoAudioOutputMode.AudioSource Sends the embedded audio into a specified AudioSource. If you set the output mode to VideoAudioOutputMode.AudioSource, Unity ignores all AudioSource fields except mute. This is because 3D spatialization of video playback isn’t available on the web.

Video formats

Unity supports the following common video file formats:

Format Extensions
MPEG–4 Part 14 .mp4
MPEG–4 file used for video downloaded from the Apple iTunes store .m4v
Apple’s QuickTime movie format .mov
Moving Picture Experts Group (MPEG) .mpg
MPEG video .mpeg
WebM video .webm
Ogg video file .ogv

The only exception to this restriction is if the video URL has no file name extension, in which case, the browser plays the video without any restrictions.

Video clips

VideoClips aren’t supported on WebGL. Typically, when creating a sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
, you import a VideoClip to your Unity project using VideoClipImporter, which is convenient if you want to reuse the same VideoClip across several platforms. When building a WebGL game that has VideoClip attached however, the Unity console logs the following warning for each VideoClip found in the game:

Embedded video clips are not supported by the WebGL player: %s. \nUse the Video Player component's URL option instead. Where %s is replaced by the video clip name. At runtime, if your game has VideoClips assigned, then Unity logs a warning message in the developer console of your web browser.

Additional resources:

Audio in WebGL
Embedded resources in WebGL
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961