Skip to content

Commit

Permalink
Add documentation on seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed May 22, 2024
1 parent 94bfd34 commit 7ed8e5a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions pages/advanced/timing-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,49 @@ var time = player.time();

## Seeking

dash.js provides two API endpoints to change the current playback position, namely `seek()`
and `seekToPresentationTime()`. Both methods are available via the `MediaPlayer` class. As an example:

````js
var video = document.querySelector('video');
var player = dashjs.MediaPlayer().create();
player.initialize(video, url, false);
player.seek(10)
````

While the `seek()` method expects values relative to `DVRWindow.start` the `seekToPresentationTime()` works with
absolute presentation timestamps. Two examples to illustrate this behavior are depicted in the sections below.

### VoD

For VoD playback both `seek()` and `seekToPresentationTime()` work in the same way and can be used interchangeable. This
is due to the fact the DVR window for VoD spans over the whole duration of the content.

![playback-time-vod]({{site.baseurl}}/assets/images/seek-api-vod.jpg)

### Live

For live playback the `seek()` method expects values relative to the start of the DVR window.
Internally `DVRWindow.start` is added to the provided value. The `seekToPresentationTime()` method uses absolute presentation timestamps.

![playback-time-vod]({{site.baseurl}}/assets/images/seek-api-live.jpg)

As an example, the following two code snippets each trigger a seek 20 seconds behind the live edge.

##### seek()
````js
var video = document.querySelector('video');
var player = dashjs.MediaPlayer().create();
player.initialize(video, url, false);
var duration = player.duration()
player.seek(duration - 20);
````

##### seekToPresentationTime()
````js
var video = document.querySelector('video');
var player = dashjs.MediaPlayer().create();
player.initialize(video, url, false);
var dvrWindowEnd = player.getDvrWindow().end
player.seekToPresentationTime(dvrWindowEnd - 20);
````

0 comments on commit 7ed8e5a

Please sign in to comment.