Proper Video Player Documentation

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#

SignatureDescription
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#

SignatureDescription
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#

PropertyTypeDescription
IsOpenbooltrue after a source has opened successfully.
IsPlaying / IsPaused / IsEndedboolCurrent playback state reported by the active backend.
IsMutedboolRequested mute state. Temporary muting used for autoplay recovery does not change this value.
IsLoopingboolRequested looping state.
PlaybackRatefloatPlayback rate configured through the component or SetPlaybackRate.
VolumefloatCurrent volume in the range 0–1, independent of mute.
PreservesPitchboolCurrent browser pitch-preservation state. Always false on the fallback backend.
CurrentTime / DurationdoublePlayback position and finite duration in seconds. Sources with an indefinite duration, such as live streams, report a duration of 0 on WebGL.
VideoWidth / VideoHeightintIntrinsic video dimensions. Query after OnLoadedMetadata and again after OnResized.
CurrentTextureTextureTexture that receives decoded video frames.
RequiresVerticalFlipbooltrue when the backend writes frames bottom-up. A configured RawImage output is adjusted automatically.
CurrentUrlstringURL passed to the most recent Open call.
CurrentSourcestringResolved URL reported by the active backend. It may differ from CurrentUrl after a redirect.
NetworkStateVideoNetworkStateHTML media network state on WebGL. The fallback approximates the state as Empty, Loading, or Idle.
ReadyStateintHTMLMediaElement.readyState (0–4) on WebGL; 0 or 4 on the fallback backend.
BufferedAheaddoubleSeconds buffered ahead of the playhead. Returns -1 when unavailable on the fallback backend; 0 indicates that no data is buffered at the current position.
PresentedFramesdoubleMonotonic count of presented frames, or -1 when the platform does not expose a counter.
DecodedFrames / DroppedFramesdoubleDecoder counters on supported browsers. Both return -1 on the fallback backend.
LastPresentedTimedoubleBest available timestamp for the currently presented frame. Uses requestVideoFrameCallback metadata on supported browsers and falls back to backend timing data.
UploadMicrosecondsdoubleSmoothed CPU submission time per WebGL texture upload, or -1 before an upload and on the fallback backend.
UploadPathVideoUploadPathMechanism used to determine when a WebGL texture upload is required. Returns Unknown on the fallback backend.
UploadViaWebGpubooltrue when frames are uploaded through the experimental Unity WebGPU path.
SupportsRequestHeadersbooltrue 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.

EventType
OnOpened, OnPlaybackStarted, OnEnded, OnSeeked, OnSeeking, OnPausedUnityEvent
OnLoadedMetadata, OnDurationChanged, OnResized, OnCanPlay, OnCanPlayThrough, OnWaiting, OnStalled, OnRateChanged, OnVolumeChangedUnityEvent
OnError, OnRecoveryAttemptedUnityEvent<string>

Enums#

EnumValuesUsed by
MediaCanPlayNo, Maybe, ProbablyCanPlayType
VideoSourceTypeAuto, Progressive, Hls, DashOpen, DetectSourceType, IsStreamingSupported
TimeRangeKindBuffered, Seekable, PlayedTime-range methods
VideoNetworkStateEmpty, Idle, Loading, NoSourceNetworkState
VideoPreloadNone, Metadata, AutoWebGLVideoBridge.SetPreload
VideoUploadPathUnknown, VideoFrameCallback, FrameCounter, ContinuousUploadPath

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.

FieldTypeDefaultDescription
enabledbooltrueEnables automatic playback recovery.
checkIntervalSecondsfloat1Time between health checks.
muteDanceAtPausedChecksint2Paused checks before attempting muted playback on WebGL.
kickAtStalledChecksint3Stalled checks before a pause-and-play recovery.
seekFlushAtStalledChecksint6Stalled checks before seeking to the current time to flush the decoder.
reloadAtStalledChecksint9Stalled or paused checks before reloading the source.
reloadRetryEveryChecksint30Checks 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 groupMembers
ConstructorWebGLVideoBridge(RenderTexture target, bool muted, bool looping)
Source and playbackSetSource(url[, type]), Play(), Pause(), Reload(), Seek(seconds), FastSeek(seconds), SetPreload(preload)
Output and lifetimeUploadFrameIfDirty(), SetTargetTexture(target), Dispose()
Playback settersSetMuted, SetLooping, SetPlaybackRate, SetVolume, SetPreservesPitch
Request configurationSetRequestHeader, ClearRequestHeaders, SetUseCredentials
State gettersIsPaused(), IsEnded(), ReadyState(), NetworkState(), Time(), Duration(), PlaybackRate(), Volume(), PreservesPitch(), VideoWidth(), VideoHeight(), CurrentSrc()
Range and diagnostics gettersGetTimeRangeCount(), GetTimeRangeStart(), GetTimeRangeEnd(), BufferedAhead(), FramesPresented(), DroppedFrames(), DecodedFrames(), LastPresentedMediaTime(), UploadMicroseconds(), UploadCount(), UploadPath(), UploadViaWebGpu(), ErrorCode(), ErrorMessage()
PropertiesIsMuted, IsLooping, PlayRequested, UseCredentials
EventsLoadedData, ErrorRaised, PlaybackStarted, Ended, Seeked, Seeking, LoadedMetadata, CanPlay, CanPlayThrough, Waiting, Stalled, Paused, RateChanged, VolumeChanged, DurationChanged, Resized
Static methodsCanPlayType(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)