Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-7392 FEC-7882): Live+DVR - unavailable time shown in the seekbar #46

Merged
merged 4 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/hls-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,15 +601,29 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
}

/**
* Get the duration in seconds.
* @returns {Number} - The playback duration.
* Get the start time of DVR window in live playback in seconds.
* @returns {Number} - start time of DVR window.
* @public
*/
get duration(): number {
getStartTimeOfDvrWindow(): number {
if (this.isLive()) {
return this._getLiveEdge();
try {
const nextLoadLevel = this._hls.levels[this._hls.nextLoadLevel],
details = nextLoadLevel.details,
fragments = details.fragments,
fragLength = fragments.length,
start = fragments[0].start + fragments[0].duration,
end = fragments[fragLength - 1].start + fragments[fragLength - 1].duration,
maxLatency = this._hls.config.liveMaxLatencyDuration !== undefined ? this._hls.config.liveMaxLatencyDuration : this._hls.config.liveMaxLatencyDurationCount * details.targetduration,
minPosToSeek = Math.max(start - this._hls.config.maxFragLookUpTolerance, end - maxLatency);
return minPosToSeek;
}
catch (e) {
HlsAdapter._logger.debug('Unable obtain the start of DVR window');
return 0;
}
} else {
return super.duration;
return 0;
}
}
}
56 changes: 23 additions & 33 deletions test/src/hls-adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,10 @@ describe('HlsAdapter Instance - seekToLiveEdge', function () {
});
});

describe('HlsAdapter Instance - get duration', function () {
describe('HlsAdapter Instance - _getLiveEdge', function () {

let hlsAdapterInstance;
let video;
let vodSource = hls_sources.ElephantsDream;
let liveSource = hls_sources.Live;
let config;
let sandbox;
Expand All @@ -552,37 +551,43 @@ describe('HlsAdapter Instance - get duration', function () {
});
});

it('should return video tag duration for VOD', (done) => {
hlsAdapterInstance = HlsAdapter.createAdapter(video, vodSource, config);
it('should return live edge for liveSyncDuration = 60', (done) => {
config.playback.options.html5.hls.liveSyncDuration = 60;
hlsAdapterInstance = HlsAdapter.createAdapter(video, liveSource, config);
hlsAdapterInstance.load().then(() => {
hlsAdapterInstance._videoElement.addEventListener('durationchange', () => {
if (isNaN(video.duration)) {
if (video.duration > 60) {
hlsAdapterInstance._getLiveEdge().should.be.equal(video.duration - 60);
done();
} else {
hlsAdapterInstance.duration.should.be.equal(video.duration);
done();
hlsAdapterInstance._getLiveEdge().should.be.equal(0);
}
});
});
});

it('should return live duration for live', (done) => {
it('should return live edge for liveSyncDurationCount = 5', (done) => {
config.playback.options.html5.hls.liveSyncDurationCount = 5;
hlsAdapterInstance = HlsAdapter.createAdapter(video, liveSource, config);
hlsAdapterInstance.load().then(() => {
hlsAdapterInstance._videoElement.addEventListener('durationchange', () => {
if (video.duration > 40) {
hlsAdapterInstance.duration.should.be.equal(video.duration - 3 * hlsAdapterInstance._hls.levels[0].details.targetduration);
let delay = 5 * hlsAdapterInstance._hls.levels[0].details.targetduration;
if (video.duration > delay) {
hlsAdapterInstance._getLiveEdge().should.be.equal(video.duration - delay);
done();
} else {
hlsAdapterInstance._getLiveEdge().should.be.equal(0);
}
});
});
});
});

describe('HlsAdapter Instance - _getLiveEdge', function () {
describe('HlsAdapter Instance - getStartTimeOfDvrWindow', function () {

let hlsAdapterInstance;
let video;
let vodSource = hls_sources.ElephantsDream;
let liveSource = hls_sources.Live;
let config;
let sandbox;
Expand All @@ -603,34 +608,19 @@ describe('HlsAdapter Instance - _getLiveEdge', function () {
});
});

it('should return live edge for liveSyncDuration = 60', (done) => {
config.playback.options.html5.hls.liveSyncDuration = 60;
hlsAdapterInstance = HlsAdapter.createAdapter(video, liveSource, config);
it('should return 0 for VOD', (done) => {
hlsAdapterInstance = HlsAdapter.createAdapter(video, vodSource, config);
hlsAdapterInstance.load().then(() => {
hlsAdapterInstance._videoElement.addEventListener('durationchange', () => {
if (video.duration > 60) {
hlsAdapterInstance._getLiveEdge().should.be.equal(video.duration - 60);
done();
} else {
hlsAdapterInstance._getLiveEdge().should.be.equal(0);
}
});
hlsAdapterInstance.getStartTimeOfDvrWindow().should.equal(0);
done();
});
});

it('should return live edge for liveSyncDurationCount = 5', (done) => {
config.playback.options.html5.hls.liveSyncDurationCount = 5;
it('should return the start of DVR window for live', (done) => {
hlsAdapterInstance = HlsAdapter.createAdapter(video, liveSource, config);
hlsAdapterInstance.load().then(() => {
hlsAdapterInstance._videoElement.addEventListener('durationchange', () => {
let delay = 5 * hlsAdapterInstance._hls.levels[0].details.targetduration;
if (video.duration > delay) {
hlsAdapterInstance._getLiveEdge().should.be.equal(video.duration - delay);
done();
} else {
hlsAdapterInstance._getLiveEdge().should.be.equal(0);
}
});
hlsAdapterInstance.getStartTimeOfDvrWindow().should.not.equal(0);
done();
});
});
});
Expand Down