Skip to content

Commit

Permalink
feat: support dash live (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
yairans committed Aug 29, 2017
1 parent a844b81 commit 0e0e97f
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 13 deletions.
61 changes: 61 additions & 0 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,26 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
return shakaConfig.abr.enabled;
}

/**
* Seeking to live edge.
* @function seekToLiveEdge
* @returns {void}
* @public
*/
seekToLiveEdge(): void {
this._videoElement.currentTime = this._shaka.seekRange().end;
}

/**
* Checking if the current playback is live.
* @function isLive
* @returns {boolean} - Whether playback is live.
* @public
*/
isLive(): boolean {
return this._shaka.isLive();
}

/**
* An handler to shaka adaptation event
* @function _onAdaptation
Expand Down Expand Up @@ -458,6 +478,47 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
}
return "";
}

/**
* Get the current time in seconds.
* @returns {Number} - The current playback time.
* @public
*/
get currentTime(): number {
if (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.isLive()) {
this._videoElement.currentTime = this._shaka.seekRange().start + to;
} else {
super.currentTime = to;
}
}

/**
* Get the duration in seconds.
* @returns {Number} - The playback duration.
* @public
*/
get duration(): number {
if (this.isLive()) {
let seekRange = this._shaka.seekRange();
return seekRange.end - seekRange.start;
} else {
return super.duration;
}
}
}

// Register DashAdapter to the media source adapter manager
Expand Down
Loading

0 comments on commit 0e0e97f

Please sign in to comment.