Skip to content

Commit

Permalink
postpone fragment delaying until just before sending xhr request
Browse files Browse the repository at this point in the history
  • Loading branch information
spiterikevin committed Feb 20, 2016
1 parent d01daa9 commit 3768a7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/streaming/FragmentLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,15 @@ function FragmentLoader(config) {
}
};

req.send();
//Adds the ability to delay single fragment loading time to control buffer.
let now = new Date().getTime();
if (now < request.delayLoadingTime) {
setTimeout(function () {
req.send();
}, (request.delayLoadingTime - now) );
} else {
req.send();
}
}

function checkForExistence(request) {
Expand Down
10 changes: 0 additions & 10 deletions src/streaming/models/FragmentModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,8 @@ function FragmentModel(config) {
}

function executeRequest(request) {
var now = new Date().getTime();

if (!request) return;

//Adds the ability to delay single fragment loading time to control buffer.
if (now < request.delayLoadingTime ) {
delayLoadingTimeout = setTimeout(function () {
executeRequest(request);
}, (request.delayLoadingTime - now) );
return;
}

switch (request.action) {
case FragmentRequest.ACTION_COMPLETE:
// Stream has completed, execute the corresponding callback
Expand Down

1 comment on commit 3768a7a

@spiterikevin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a stream ends during a delay for loading a fragment, the fragment might then not be loaded correctly. This can be resolved by moving the delay from the FragmentModel to the FragmentLoader. It works by allowing the xhr request to be generated right away, because if the stream ends then there might be a problem generating the request. The delay is then inserted just before sending the xhr request.

After this change, there will no longer be a need for hooking the PLAYBACK_SEEKING event in the FragmentModel.

Please sign in to comment.