> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ofauth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Play DRM video

> Integrate Widevine DASH playback and descriptor renewal with Shaka Player

Use the media item's `playback` descriptor to load protected video in your existing player flow. This guide uses [Shaka Player](https://shaka-project.github.io/shaka-player/docs/api/tutorial-basic-usage.html). See [DRM support](https://docs.ofauth.com/v3/guides/drm-support.md) for supported media and environments.

## 1. Obtain the media through Access

From your backend, call the existing Access operation with the viewer's authorized linked account. For a post, use `posts:read`:

```bash theme={null}
	curl 'https://api.ofauth.com/v3/access/posts/123' \
		-H "Authorization: Bearer $ACCESS_TOKEN" \
		-H "x-linked-account-id: $LINKED_ACCOUNT_ID"
```

Select the intended media item from the response. Pass its `playback` descriptor to your frontend through your application's authenticated response. Keep your OAuth refresh token and OnlyFans session out of the player.

If the item has no `playback`, use your existing ordinary-media path only when the response contains a viewable, unprotected media URL. Do not synthesize a descriptor from a raw manifest.

## 2. Attach the player

Install Shaka in your frontend project:

```bash theme={null}
	npm install shaka-player
```

Render a video element with controls. In the following example, `video` is that element and `playback` is the descriptor from step 1.

```javascript theme={null}
	import shaka from "shaka-player";

	shaka.polyfill.installAll();
	if (!shaka.Player.isBrowserSupported()) {
		throw new Error("This browser does not support the video player");
	}

	const player = new shaka.Player();
	await player.attach(video);
	player.addEventListener("error", (event) => {
		console.error("Playback error", event.detail.code);
	});
	player.configure({ drm: { servers: playback.licenseServers } });
	await player.load(playback.manifestUrl, undefined, playback.mimeType);
```

Use your existing Play control to call `video.play()`. The basic browser support check does not guarantee Widevine or codec support; handle errors from `player.load()` too.

Shaka sends the binary license challenge to the configured server. Do not add a JSON wrapper or parse the license as JSON. The [Shaka DRM configuration guide](https://shaka-project.github.io/shaka-player/docs/api/tutorial-drm-config.html) describes the player setting.

Use the returned URLs unchanged. No player request filter, cross-site cookie configuration, or browser origin override is required.

## 3. Renew without losing the playback position

Keep the current descriptor in a mutable `playback` variable. Add a renewal function next to the player initialization:

```javascript theme={null}
	let renewal;

	function renewPlayback() {
		if (renewal) return renewal;
		renewal = (async () => {
			const response = await fetch(playback.renewUrl, {
				credentials: "omit",
				cache: "no-store"
			});
			if (!response.ok) {
				throw new Error(`Playback renewal HTTP ${response.status}`);
			}
			const next = await response.json();
			const position = video.currentTime;
			const wasPaused = video.paused;
			player.configure({ drm: { servers: next.licenseServers } });
			await player.load(next.manifestUrl, position, next.mimeType);
			playback = next;
			if (wasPaused) video.pause();
			else await video.play();
		})().finally(() => { renewal = undefined; });
		return renewal;
	}
```

Wire the function into your player's lifecycle:

1. Schedule renewal before `Date.parse(playback.expiresAt)`, for example 60 seconds early.
2. After each renewal, schedule from the replacement descriptor's expiry.
3. Before resuming a long-paused video, renew if the descriptor has expired or is near expiry. Background timers can be delayed.
4. If renewal returns an access denial, stop retries and refresh access through your backend. After the renewal URL expires, fetch a new media response.
5. When the video component unmounts, clear its renewal timer, wait for an in-flight renewal to settle, and call `await player.destroy()`.

Do not run renewal and player destruction at the same time. The function above shares one in-flight renewal between callers.

## 4. Verify playback on your application's origin

Use a Live linked account and a DRM video that account can view. Open your real application on HTTPS or localhost.

Confirm that the video advances, audio plays, and seeking works. Renew the descriptor and check that playback resumes at the prior position. Then revoke the relevant access and verify that subsequent media and license requests are denied. Previously buffered frames can remain visible.

Inspect the manifest, resource, license, and renewal requests separately when playback fails. See [Playback failures](https://docs.ofauth.com/v3/guides/drm-support.md#playback-failures) for recovery behavior.

For retained media, take the descriptor from the Vault+ variant and use the same player integration. See [Retain DRM video in Vault+](https://docs.ofauth.com/v3/guides/vault-plus-drm.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.