API Reference
Public C# API for the ProperVideoPlayerWebGL namespace in version 1.0.0. The
same descriptions are available as XML documentation in supported IDEs.
ProperVideoPlayer#
[AddComponentMenu("Video/Proper Video Player (WebGL)")] [DisallowMultipleComponent] public sealed class
ProperVideoPlayer : MonoBehaviour
public const string Version = "1.0.0" identifies the installed asset version.
Methods#
| Signature | Description |
void Open(string url) | Opens the source and requests playback after the first frame is available. On WebGL, URLs ending in .m3u8 or .mpd are detected as HLS or DASH. |
void Open(string url, bool playWhenReady) | Opens the source and optionally starts playback when ready. A subsequent call supersedes a pending open; the previous frame remains visible until the replacement source is ready. |
void Open(string url, bool playWhenReady, VideoSourceType sourceType) | Opens a source using an explicit type. Use this overload for HLS or DASH URLs that do not have a recognizable extension. |
void OpenConfiguredSource() | Opens the source configured on the component and requests playback. |
void Play() / void Pause() | Requests playback or pauses the current source. |
void Stop() | Pauses playback and seeks to the beginning of the source. |
void Seek(double seconds) | Seeks to a time in seconds. OnSeeked is invoked when the operation completes, and playback resumes if it was requested before the seek. |
void FastSeek(double seconds) | Uses the browser's faster, less precise seek operation when available and otherwise performs a normal seek. Intended for scrubbing. |
void SetMuted(bool muted) / void SetLooping(bool looping) | Updates the requested mute or looping state. |
void SetPlaybackRate(float rate) | Sets the playback rate. The serialized component setting exposes a range of 0.25× to 4×. |
void SetVolume(float volume) | Sets volume in the range 0–1. Volume and mute are independent. |
void SetPreservesPitch(bool preserve) | Requests pitch preservation when the playback rate is not 1×. This is supported by the WebGL backend and has no effect on the fallback backend. |
void SetRequestHeader(string name, string value) | Sets a header for WebGL HLS and DASH playlist, segment, and key requests. Call before Open. Setting the same header again updates subsequent requests; passing null as the value removes it. The method has no effect outside WebGL. |
void ClearRequestHeaders() | Removes all headers configured with SetRequestHeader. |
void SetUseCredentials(bool useCredentials) | Enables or disables credentialed CORS requests on WebGL. Call before Open. The method has no effect outside WebGL. |
int GetTimeRangeCount(TimeRangeKind kind) | Returns the number of buffered, seekable, or played ranges. The fallback backend exposes only the seekable range. |
double GetTimeRangeStart(TimeRangeKind kind, int index) | Returns the start of a range in seconds, or 0 when the index is invalid. |
double GetTimeRangeEnd(TimeRangeKind kind, int index) | Returns the end of a range in seconds, or 0 when the index is invalid. |
Static methods#
| Signature | Description |
static MediaCanPlay CanPlayType(string mimeType) | Queries browser support for a MIME type such as "video/webm; codecs=vp9". Returns Maybe outside WebGL builds. |
static VideoSourceType DetectSourceType(string url) | Classifies a URL by its extension: .m3u8 as HLS, .mpd as DASH, and all other URLs as progressive media. |
static bool IsStreamingSupported(VideoSourceType type) | Reports whether the library supports the source type on the current platform. WebGL supports HLS and DASH; the fallback supports HLS on iOS, tvOS, macOS, and Android, but does not support DASH. This method does not test a specific codec or URL. |
Properties#
| Property | Type | Description |
IsOpen | bool | true after a source has opened successfully. |
IsPlaying / IsPaused / IsEnded | bool | Current playback state reported by the active backend. |
IsMuted | bool | Requested mute state. Temporary muting used for autoplay recovery does not change this value. |
IsLooping | bool | Requested looping state. |
PlaybackRate | float | Playback rate configured through the component or SetPlaybackRate. |
Volume | float | Current volume in the range 0–1, independent of mute. |
PreservesPitch | bool | Current browser pitch-preservation state. Always false on the fallback backend. |
CurrentTime / Duration | double | Playback position and finite duration in seconds. Sources with an indefinite duration, such as live streams, report a duration of 0 on WebGL. |
VideoWidth / VideoHeight | int | Intrinsic video dimensions. Query after OnLoadedMetadata and again after OnResized. |
CurrentTexture | Texture | Texture that receives decoded video frames. |
RequiresVerticalFlip | bool | true when the backend writes frames bottom-up. A configured RawImage output is adjusted automatically. |
CurrentUrl | string | URL passed to the most recent Open call. |
CurrentSource | string | Resolved URL reported by the active backend. It may differ from CurrentUrl after a redirect. |
NetworkState | VideoNetworkState | HTML media network state on WebGL. The fallback approximates the state as Empty, Loading, or Idle. |
ReadyState | int | HTMLMediaElement.readyState (0–4) on WebGL; 0 or 4 on the fallback backend. |
BufferedAhead | double | Seconds buffered ahead of the playhead. Returns -1 when unavailable on the fallback backend; 0 indicates that no data is buffered at the current position. |
PresentedFrames | double | Monotonic count of presented frames, or -1 when the platform does not expose a counter. |
DecodedFrames / DroppedFrames | double | Decoder counters on supported browsers. Both return -1 on the fallback backend. |
LastPresentedTime | double | Best available timestamp for the currently presented frame. Uses requestVideoFrameCallback metadata on supported browsers and falls back to backend timing data. |
UploadMicroseconds | double | Smoothed CPU submission time per WebGL texture upload, or -1 before an upload and on the fallback backend. |
UploadPath | VideoUploadPath | Mechanism used to determine when a WebGL texture upload is required. Returns Unknown on the fallback backend. |
UploadViaWebGpu | bool | true when frames are uploaded through the experimental Unity WebGPU path. |
SupportsRequestHeaders | bool | true when custom headers can be attached to HLS or DASH requests. This is currently available only on WebGL. |
Events#
All component events are UnityEvent properties and can be configured in the Inspector or with
AddListener. See Events for invocation semantics and platform support.
| Event | Type |
OnOpened, OnPlaybackStarted, OnEnded, OnSeeked, OnSeeking, OnPaused | UnityEvent |
OnLoadedMetadata, OnDurationChanged, OnResized, OnCanPlay, OnCanPlayThrough, OnWaiting, OnStalled, OnRateChanged, OnVolumeChanged | UnityEvent |
OnError, OnRecoveryAttempted | UnityEvent<string> |
Enums#
| Enum | Values | Used by |
MediaCanPlay | No, Maybe, Probably | CanPlayType |
VideoSourceType | Auto, Progressive, Hls, Dash | Open, DetectSourceType, IsStreamingSupported |
TimeRangeKind | Buffered, Seekable, Played | Time-range methods |
VideoNetworkState | Empty, Idle, Loading, NoSource | NetworkState |
VideoPreload | None, Metadata, Auto | WebGLVideoBridge.SetPreload |
VideoUploadPath | Unknown, VideoFrameCallback, FrameCounter, Continuous | UploadPath |
WatchdogSettings#
[Serializable] public sealed class WatchdogSettings configures automatic playback recovery.
Thresholds are measured in health checks, separated by checkIntervalSeconds. See
Playback Watchdog for the recovery sequence.
| Field | Type | Default | Description |
enabled | bool | true | Enables automatic playback recovery. |
checkIntervalSeconds | float | 1 | Time between health checks. |
muteDanceAtPausedChecks | int | 2 | Paused checks before attempting muted playback on WebGL. |
kickAtStalledChecks | int | 3 | Stalled checks before a pause-and-play recovery. |
seekFlushAtStalledChecks | int | 6 | Stalled checks before seeking to the current time to flush the decoder. |
reloadAtStalledChecks | int | 9 | Stalled or paused checks before reloading the source. |
reloadRetryEveryChecks | int | 30 | Checks between subsequent reload attempts. |
WebGLVideoBridge#
public sealed class WebGLVideoBridge : IDisposable is a low-level wrapper around a hidden HTML
<video> element. Its platform calls are inert outside WebGL builds. Most integrations should use
ProperVideoPlayer; see WebGLVideoBridge when direct control is
required.
| Member group | Members |
| Constructor | WebGLVideoBridge(RenderTexture target, bool muted, bool looping) |
| Source and playback | SetSource(url[, type]), Play(), Pause(), Reload(), Seek(seconds), FastSeek(seconds), SetPreload(preload) |
| Output and lifetime | UploadFrameIfDirty(), SetTargetTexture(target), Dispose() |
| Playback setters | SetMuted, SetLooping, SetPlaybackRate, SetVolume, SetPreservesPitch |
| Request configuration | SetRequestHeader, ClearRequestHeaders, SetUseCredentials |
| State getters | IsPaused(), IsEnded(), ReadyState(), NetworkState(), Time(), Duration(), PlaybackRate(), Volume(), PreservesPitch(), VideoWidth(), VideoHeight(), CurrentSrc() |
| Range and diagnostics getters | GetTimeRangeCount(), GetTimeRangeStart(), GetTimeRangeEnd(), BufferedAhead(), FramesPresented(), DroppedFrames(), DecodedFrames(), LastPresentedMediaTime(), UploadMicroseconds(), UploadCount(), UploadPath(), UploadViaWebGpu(), ErrorCode(), ErrorMessage() |
| Properties | IsMuted, IsLooping, PlayRequested, UseCredentials |
| Events | LoadedData, ErrorRaised, PlaybackStarted, Ended, Seeked, Seeking, LoadedMetadata, CanPlay, CanPlayThrough, Waiting, Stalled, Paused, RateChanged, VolumeChanged, DurationChanged, Resized |
| Static methods | CanPlayType(mimeType), ConfigureStreamingLibraries(hlsUrl, dashUrl) |
Async extensions (UniTask)#
public static class ProperVideoPlayerAsyncExtensions is compiled only when
PVPW_UNITASK_SUPPORT is defined. See UniTask Integration for setup and
cancellation behavior.
| Signature |
UniTask<bool> OpenAsync(this ProperVideoPlayer player, string url, bool playWhenReady = true, CancellationToken cancellationToken = default) |
UniTask<bool> SeekAsync(this ProperVideoPlayer player, double seconds, double timeoutSeconds = 3.0, CancellationToken cancellationToken = default) |
UniTask WaitForEndAsync(this ProperVideoPlayer player, CancellationToken cancellationToken = default) |
UniTask<bool> PlayToEndAsync(this ProperVideoPlayer player, string url, CancellationToken cancellationToken = default) |