Skip to content

Commit

Permalink
fix(FEC-7882): Live+DVR - unavailable time shown in the seekbar (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
yairans authored and Dan Ziv committed Feb 11, 2018
1 parent 4ef9c3d commit 6b04f2b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 164 deletions.
49 changes: 15 additions & 34 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
return false;
}

/**
* Returns the live edge
* @returns {number} - live edge
* @private
*/
_getLiveEdge(): number {
return this._shaka ? this._shaka.seekRange().end : NaN;
}

/**
* Seeking to live edge.
* @function seekToLiveEdge
Expand Down Expand Up @@ -654,43 +663,15 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
}

/**
* Get the current time in seconds.
* @returns {Number} - The current playback time.
* @public
*/
get currentTime(): number {
if (this._shaka && this.isLive()) {
return this._videoElement.currentTime - this._shaka.seekRange().start;
} else {
return super.currentTime;
}
}

/**
* Set the current time in seconds.
* @param {Number} to - The number to set in seconds.
* @public
* @returns {void}
*/
set currentTime(to: number): void {
if (this._shaka && this.isLive()) {
this._videoElement.currentTime = this._shaka.seekRange().start + to;
} else {
super.currentTime = to;
}
}

/**
* 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 {
if (this._shaka && this.isLive()) {
let seekRange = this._shaka.seekRange();
return seekRange.end - seekRange.start;
getStartTimeOfDvrWindow(): number {
if (this.isLive() && this._shaka) {
return this._shaka.seekRange().start;
} else {
return super.duration;
return 0;
}
}
}
178 changes: 48 additions & 130 deletions test/src/dash-adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ describe('DashAdapter: isLive', () => {
});
});

describe('DashAdapter: seekToLiveEdge', () => {
describe('DashAdapter: _getLiveEdge', () => {
let video, dashInstance, config;

beforeEach(() => {
Expand All @@ -737,130 +737,16 @@ describe('DashAdapter: seekToLiveEdge', () => {
TestUtils.removeVideoElementsFromTestPage();
});

it('should seek to live edge', (done) => {
it('should return the live edge', (done) => {
dashInstance = DashAdapter.createAdapter(video, liveSource, config);
dashInstance.load().then(() => {
video.currentTime = dashInstance._shaka.seekRange().start;
((dashInstance._shaka.seekRange().end - video.currentTime) >= 30).should.be.true;
dashInstance.seekToLiveEdge();
((dashInstance._shaka.seekRange().end - video.currentTime) <= 1).should.be.true;
done();
});
});

it.skip('should seek to live edge - DVR', (done) => {
dashInstance = DashAdapter.createAdapter(video, dvrSource, config);
dashInstance.load().then(() => {
video.currentTime = dashInstance._shaka.seekRange().start;
((dashInstance._shaka.seekRange().end - video.currentTime) > 30).should.be.true;
dashInstance.seekToLiveEdge();
((dashInstance._shaka.seekRange().end - video.currentTime) < 1).should.be.true;
dashInstance._getLiveEdge().should.equal(dashInstance._shaka.seekRange().end);
done();
});
});
});

describe('DashAdapter: get currentTime', () => {
let video, dashInstance, config;

beforeEach(() => {
video = document.createElement("video");
config = {playback: {options: {html5: {dash: {}}}}};
});

afterEach((done) => {
dashInstance.destroy().then(() => {
dashInstance = null;
done();
});
});

after(() => {
TestUtils.removeVideoElementsFromTestPage();
});

it('should return video tag current time for VOD', (done) => {
dashInstance = DashAdapter.createAdapter(video, vodSource, config);
dashInstance.load().then(() => {
dashInstance.currentTime.should.be.equal(video.currentTime);
video.currentTime += 15;
dashInstance.currentTime.should.be.equal(video.currentTime);
done();
});
});

it('should return live current time for live', (done) => {
dashInstance = DashAdapter.createAdapter(video, liveSource, config);
dashInstance.load().then(() => {
dashInstance.currentTime.should.be.equal(video.currentTime - dashInstance._shaka.seekRange().start);
video.currentTime += 15;
dashInstance.currentTime.should.be.equal(video.currentTime - dashInstance._shaka.seekRange().start);
done();
});
});

it.skip('should return live current time for live + DVR', (done) => {
dashInstance = DashAdapter.createAdapter(video, dvrSource, config);
dashInstance.load().then(() => {
dashInstance.currentTime.should.be.equal(video.currentTime - dashInstance._shaka.seekRange().start);
video.currentTime += 15;
dashInstance.currentTime.should.be.equal(video.currentTime - dashInstance._shaka.seekRange().start);
done();
});
});
});

describe('DashAdapter: set currentTime', () => {
let video, dashInstance, config;

beforeEach(() => {
video = document.createElement("video");
config = {playback: {options: {html5: {dash: {}}}}};
});

afterEach((done) => {
dashInstance.destroy().then(() => {
dashInstance = null;
done();
});
});

after(() => {
TestUtils.removeVideoElementsFromTestPage();
});

it('should set current time for VOD', (done) => {
dashInstance = DashAdapter.createAdapter(video, vodSource, config);
dashInstance.load().then(() => {
let ct = video.currentTime;
dashInstance.currentTime += 15;
video.currentTime.should.be.equal(ct + 15);
done();
});
});

it('should set live current time for live', (done) => {
dashInstance = DashAdapter.createAdapter(video, liveSource, config);
dashInstance.load().then(() => {
let ct = video.currentTime;
dashInstance.currentTime += 15;
video.currentTime.should.be.equal(ct + 15);
done();
});
});

it.skip('should set live current time for live + DVR', (done) => {
dashInstance = DashAdapter.createAdapter(video, dvrSource, config);
dashInstance.load().then(() => {
let ct = video.currentTime;
dashInstance.currentTime += 15;
video.currentTime.should.be.equal(ct + 15);
done();
});
});
});

describe('DashAdapter: get duration', () => {
describe('DashAdapter: seekToLiveEdge', () => {
let video, dashInstance, config;

beforeEach(() => {
Expand All @@ -879,26 +765,24 @@ describe('DashAdapter: get duration', () => {
TestUtils.removeVideoElementsFromTestPage();
});

it('should return video tag duration for VOD', (done) => {
dashInstance = DashAdapter.createAdapter(video, vodSource, config);
dashInstance.load().then(() => {
dashInstance.duration.should.be.equal(video.duration);
done();
});
});

it('should return live duration for live', (done) => {
it('should seek to live edge', (done) => {
dashInstance = DashAdapter.createAdapter(video, liveSource, config);
dashInstance.load().then(() => {
dashInstance.duration.should.be.equal(dashInstance._shaka.seekRange().end - dashInstance._shaka.seekRange().start);
video.currentTime = dashInstance._shaka.seekRange().start;
((dashInstance._shaka.seekRange().end - video.currentTime) >= 30).should.be.true;
dashInstance.seekToLiveEdge();
((dashInstance._shaka.seekRange().end - video.currentTime) <= 1).should.be.true;
done();
});
});

it.skip('should return live duration for live + DVR', (done) => {
it.skip('should seek to live edge - DVR', (done) => {
dashInstance = DashAdapter.createAdapter(video, dvrSource, config);
dashInstance.load().then(() => {
dashInstance.duration.should.be.equal(dashInstance._shaka.seekRange().end - dashInstance._shaka.seekRange().start);
video.currentTime = dashInstance._shaka.seekRange().start;
((dashInstance._shaka.seekRange().end - video.currentTime) > 30).should.be.true;
dashInstance.seekToLiveEdge();
((dashInstance._shaka.seekRange().end - video.currentTime) < 1).should.be.true;
done();
});
});
Expand Down Expand Up @@ -1022,5 +906,39 @@ describe('DashAdapter: _onPlaying', () => {
});
});

describe('DashAdapter: getStartTimeOfDvrWindow', () => {
let video, dashInstance, config;

beforeEach(() => {
video = document.createElement("video");
config = {playback: {options: {html5: {dash: {}}}}};
});

afterEach((done) => {
dashInstance.destroy().then(() => {
dashInstance = null;
done();
});
});

after(() => {
TestUtils.removeVideoElementsFromTestPage();
});

it('should return 0 for VOD', (done) => {
dashInstance = DashAdapter.createAdapter(video, vodSource, config);
dashInstance.load().then(() => {
dashInstance.getStartTimeOfDvrWindow().should.equal(0);
done();
});
});

it('should return the start time of Dvr window for live', (done) => {
dashInstance = DashAdapter.createAdapter(video, liveSource, config);
dashInstance.load().then(() => {
dashInstance.getStartTimeOfDvrWindow().should.equal(dashInstance._shaka.seekRange().start);
done();
});
});
});

0 comments on commit 6b04f2b

Please sign in to comment.