Proper Video Player Documentation

WebGLVideoBridge advanced

WebGLVideoBridge is the low-level C# wrapper for the hidden browser <video> element. Use it when direct lifecycle and texture-upload control is required. For standard playback, use the ProperVideoPlayer component, which adds texture management, a watchdog, and a non-WebGL fallback.

Lifecycle#

  1. Create the bridge with a dedicated RenderTexture.
  2. Configure preload, credentials, or request headers before calling SetSource.
  3. Call UploadFrameIfDirty() once per rendered frame. It returns true only when a frame was uploaded.
  4. Call Dispose() when the bridge is no longer needed. Disposal removes the browser media element.
using ProperVideoPlayerWebGL;
using UnityEngine;

public sealed class LayeredVideo : MonoBehaviour
{
    [SerializeField] private RenderTexture target;
    private WebGLVideoBridge bridge;

    private void Start()
    {
        bridge = new WebGLVideoBridge(target, muted: true, looping: true);
        bridge.LoadedData += () => Debug.Log("First video frame decoded");
        bridge.ErrorRaised += ReportError;
        bridge.SetSource("https://cdn.example.com/layer.webm");
        bridge.Play();
    }

    private void Update()
    {
        bridge?.UploadFrameIfDirty();
    }

    private void ReportError()
    {
        Debug.LogWarning($"Video error {bridge.ErrorCode()}: {bridge.ErrorMessage()}");
    }

    private void OnDestroy()
    {
        bridge?.Dispose();
    }
}

Texture behavior#

  • Assign a different RenderTexture to each bridge. Reusing a native texture handle is detected and logged as an error.
  • Video frames require a vertical UV flip when sampled in WebGL. For a RawImage, use uvRect = new Rect(0, 1, 1, -1).
  • On the WebGL graphics path, the native upload code replaces the texture storage with storage sized to the decoded video. The Unity-side RenderTexture descriptor does not reflect that native resize.
  • On the WebGPU graphics path, the existing texture storage is used. Recreate the target at the required size and call SetTargetTexture in response to metadata or resize events when dimensions can change.

Platform behavior#

Outside WebGL builds, the bridge methods compile to inert stubs. The class does not create Unity's VideoPlayer fallback. Use ProperVideoPlayer when the same playback feature must operate on WebGL and non-WebGL targets.

API surface#

The bridge exposes browser media events as C# events, playback and audio controls, HLS/DASH source selection, authentication settings, preload control, time-range queries, frame counters, upload diagnostics, and media-error details. Static methods provide codec probing and streaming-library configuration. See the API Reference for the complete member list.

No built-in watchdog

WebGLVideoBridge does not apply automatic recovery. Use Reload(), playback state, and frame counters to implement an application-specific policy, or use ProperVideoPlayer for the packaged watchdog.