Skip to content

Commit

Permalink
getDuration() now overridden to return hlsjs reported duration
Browse files Browse the repository at this point in the history
Also timeupdate event now always contains the actual time instead of
trying to round up to the duration when dvr wasn't being used
(incorrectly). I think the reason this was there was to make the seek
bar stick to the right when dvr wasn't being used but this might make
more sense being handled in MediaControl so that the correct values are
still reported in the event.

TODO:
- update MediaControl so that it renders the seek bar slider at the far
right when dvr is disabled.
- Figure out what do do in getPlayableStartTime() (See comment)
  • Loading branch information
tjenkinson committed Nov 16, 2015
1 parent 5d6d9d4 commit 0e5280e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/playbacks/hls/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ export default class HLS extends HTML5VideoPlayback {
get currentLevel() { return (this.hls && this.hls.currentLevel) || -1 }
set currentLevel(level) { this.hls && (this.hls.currentLevel = level) }

// for hls streams which have dvr with a sliding window,
// the content at the start of the playlist is removed as new
// content is appended at the end.
// this means the actual playable start time will increase as the
// start content is deleted
// For streams with dvr where the entire recording is kept from the
// beginning this should always return 0
getPlayableStartTime() {
// TODO this should probably just return video.seekable.start(0)
// but looks like this might have a bug/not been implemented at the moment
// https://github.com/dailymotion/hls.js/issues/65

// for now return this even though it's wrong as it works ok
// super.getDuration() should never be used for reasons
// described in https://github.com/clappr/clappr/issues/668#issuecomment-157036678
return super.getDuration() - this.playableRegionDuration
}

Expand All @@ -41,6 +55,13 @@ export default class HLS extends HTML5VideoPlayback {
this.hls.attachVideo(this.el)
}

// the duration on the video element itself should not be used
// as this does not necesarily represent the duration of the stream
// https://github.com/clappr/clappr/issues/668#issuecomment-157036678
getDuration() {
return this.playableRegionDuration
}

getCurrentTime() {
return this.el.currentTime - this.getPlayableStartTime()
}
Expand Down Expand Up @@ -76,11 +97,7 @@ export default class HLS extends HTML5VideoPlayback {
}

timeUpdated() {
if (this.dvrEnabled) {
this.trigger(Events.PLAYBACK_TIMEUPDATE, this.dvrInUse ? this.getCurrentTime() : this.playableRegionDuration, this.playableRegionDuration, this.name)
} else {
super.timeUpdated()
}
this.trigger(Events.PLAYBACK_TIMEUPDATE, this.getCurrentTime(), this.getDuration(), this.name)
}

play() {
Expand Down

0 comments on commit 0e5280e

Please sign in to comment.