Proper Video Player Documentation

UniTask Integration optional

Optional async extensions for projects that use UniTask. The runtime has no UniTask dependency unless the integration is enabled.

Requirements and setup#

Install UniTask before enabling the integration. Then open Tools → Proper Video Player → Setup and use one of the following configurations:

  • Manual define: select Enable UniTask Support to add PVPW_UNITASK_SUPPORT to the supported build targets. This works with Package Manager and source-based UniTask installations.
  • Assembly definitions: select Install Asmdefs. When UniTask is installed from the com.cysharp.unitask package, the integration assembly detects it and defines PVPW_UNITASK_SUPPORT automatically. Source-based installations still require the manual define.

The setup window reports the detected package, automatic activation, and manual-define status. Enabling the define without an available UniTask assembly causes compilation errors.

Extension methods#

MethodCompletion behavior
OpenAsync(string url, bool playWhenReady = true, CancellationToken cancellationToken = default)Returns true after the first frame is available, or false if OnError is invoked.
SeekAsync(double seconds, double timeoutSeconds = 3.0, CancellationToken cancellationToken = default)Returns true when OnSeeked is invoked, or false when the timeout expires.
WaitForEndAsync(CancellationToken cancellationToken = default)Completes on the next OnEnded event. A looping source does not raise this event.
PlayToEndAsync(string url, CancellationToken cancellationToken = default)Opens the URL, disables looping if necessary, and waits for the source to end. Returns false if opening fails; it does not restore the previous looping state.

Cancellation follows normal UniTask behavior and propagates as a cancellation exception. Each method removes its temporary event listeners when it completes or is canceled.

using System.Threading;
using Cysharp.Threading.Tasks;
using ProperVideoPlayerWebGL;

private async UniTask PlayVideoAsync(string url)
{
    CancellationToken cancellationToken = this.GetCancellationTokenOnDestroy();

    if (!await player.OpenAsync(
            url,
            playWhenReady: true,
            cancellationToken: cancellationToken))
        return;

    bool seekCompleted = await player.SeekAsync(
        12.5,
        timeoutSeconds: 3.0,
        cancellationToken: cancellationToken);

    if (!seekCompleted)
        Debug.LogWarning("The seek operation timed out.");

    await player.WaitForEndAsync(cancellationToken);
}

Concurrent operations#

The extensions complete in response to the player's shared events. Avoid starting overlapping OpenAsync or SeekAsync calls on the same player. If another Open supersedes an in-progress OpenAsync, the task completes from the first subsequent OnOpened or OnError event rather than tracking a specific URL.

Assembly-definition projects#

Without the optional assembly definitions, the enabled integration compiles into Assembly-CSharp. Projects that place their own code in assemblies should install the asset's asmdefs from the Setup window. The generated integration assembly references both ProperVideoPlayerWebGL.Runtime and UniTask; add references to the runtime and integration assemblies from the asmdef that contains the calling code.