javascriptnode.jsvideo-streaminghtml5-videodash.js

Dash.js fetches .m4s files when setting video.currentTime and results in errors. Errors when setting video.currentTime in dash.js


Basically, I need to start playing my .mpd file from a given duration using dash.js

I am able to play my .mpd file properly from start to end using dash.js in the browser. But when I want to play it from a specific duration specified in seconds, it requests a few incorrect non-existing .m4s files and results in a 404 error from the server. Below is the JS code -


var video = document.getElementById('video-' + layerId);
var player = dashjs.MediaPlayer().create();
player.initialize(video, videoUrl, true);
player.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, function() {
    video.currentTime = 88; // 
});

Error in console -

XHRLoader.js:102 - GET http://localhost:5000/videos/m4d/video_dash33.m4s 404 (NOT FOUND)

XHRLoader.js:102 - GET http://localhost:5000/videos/m4d/video_dash34.m4s 404 (NOT FOUND) XHRLoader.js:102 - GET http://localhost:5000/videos/m4d/video_dash35.m4s 404 (NOT FOUND)

Suppose I comment on my 2nd last line, // video.currentTime = 88; Then the whole video plays properly from start to end. But I need the video to start from a specific time say - 88 secs. How can I do it?


Solution

  • The error in my case was in the mpd file created by mp4box. It had an incorrect duration of SegmentTemplate=4000. Because of the incorrect duration, it was calculating non-existent .m4s chunks which led to 404 error from the server.

    Solution:
    Setting the duration in SegmentTemplate to 128000 corrected the whole thing in my case.