Skip to content

Commit e4fcc94

Browse files
authored
feat: Add canupdatestarttime to allow update the startTime safely (#8604)
Close #8506 Example of use: ``` this.player_.addEventListener('canupdatestarttime', () => { this.player_.updateStartTime(this.player_.seekRange().start + 300); }); ```
1 parent 2a063ff commit e4fcc94

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/player.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,17 @@ goog.requireType('shaka.media.PresentationTimeline');
440440
*/
441441

442442

443+
/**
444+
* @event shaka.Player.CanUpdateStartTimeEvent
445+
* @description Fired when it is safe to update the start time of a stream. You
446+
* may use this event to get the seek range and update the start time,
447+
* eg: on live streams.
448+
* @property {string} type
449+
* 'canupdatestarttime'
450+
* @exportDoc
451+
*/
452+
453+
443454
/**
444455
* @event shaka.Player.AbrStatusChangedEvent
445456
* @description Fired when the state of abr has been changed.
@@ -2831,6 +2842,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
28312842
this.streamingEngine_.applyPlayRange(
28322843
this.config_.playRangeStart, this.config_.playRangeEnd);
28332844

2845+
this.fullyLoaded_ = true;
2846+
2847+
this.dispatchEvent(shaka.Player.makeEvent_(
2848+
shaka.util.FakeEvent.EventName.CanUpdateStartTime));
2849+
28342850
const setupPlayhead = (startTime) => {
28352851
this.playhead_ = this.createPlayhead(startTime);
28362852
this.playheadObservers_ =
@@ -2989,8 +3005,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
29893005
if (this.adManager_) {
29903006
this.adManager_.onManifestUpdated(isLive);
29913007
}
2992-
2993-
this.fullyLoaded_ = true;
29943008
}
29953009

29963010
/**
@@ -3139,6 +3153,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
31393153
unloaded = true;
31403154
});
31413155

3156+
this.dispatchEvent(shaka.Player.makeEvent_(
3157+
shaka.util.FakeEvent.EventName.CanUpdateStartTime));
3158+
31423159
if (this.startTime_ != null) {
31433160
this.playhead_.setStartTime(this.startTime_);
31443161
}

lib/util/fake_event.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ shaka.util.FakeEvent.EventName = {
159159
AudioTracksChanged: 'audiotrackschanged',
160160
BoundaryCrossed: 'boundarycrossed',
161161
Buffering: 'buffering',
162+
CanUpdateStartTime: 'canupdatestarttime',
162163
Complete: 'complete',
163164
DownloadCompleted: 'downloadcompleted',
164165
DownloadFailed: 'downloadfailed',

project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ audiotrackchanged
1010
audiotrackschanged
1111
autoplaying
1212
boundarycrossed
13+
canupdatestarttime
1314
captionselectionupdated
1415
caststatuschanged
1516
clearlead

0 commit comments

Comments
 (0)