How to seek video using dash.js?

891 Views Asked by At

I am trying to play video in a HTML page.
But the video always play from the beginning.

I saved the time in a cookie and I am trying to play the video from that time.

There seems to be a seek function to achieve this?
How to play a video from a specific time using dash.js?

2

There are 2 best solutions below

0
Nicolas Migut On

I encountered the same issue. The problem is probably that you are trying to seek before the player is ready. I came up with the following solution:

dash?.on('streamInitialized', () => dash?.seek(time))

With this, seek works correctly.

0
gorkem On

Since DashJS 4.4.1, you can now use attachSource() with a second parameter to seek to a specific time after the stream is initialized:

attachSource(urlOrManifest, startTime)

startTime number | string
For VoD content the start time is relative to the start time of the first period. For live content If the parameter starts from prefix posix: it signifies the absolute time range defined in seconds of Coordinated Universal Time (ITU-R TF.460-6). This is the number of seconds since 01-01-1970 00:00:00 UTC. Fractions of seconds may be optionally specified down to the millisecond level. If no posix prefix is used the starttime is relative to MPD@availabilityStartTime