Skip to content

Commit

Permalink
feat: Expose PresentationTimeline segment availability duration throu…
Browse files Browse the repository at this point in the history
…gh Player (#6075)

Closes #2711
  • Loading branch information
avelad committed Jan 10, 2024
1 parent 272b7a9 commit 8ff5b59
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cast/cast_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ shaka.cast.CastUtils.LargePlayerGetterMethods = {
shaka.cast.CastUtils.PlayerGetterMethodsThatRequireLive = {
'getPlayheadTimeAsDate': 1,
'getPresentationStartTimeAsDate': 20,
'getSegmentAvailabilityDuration': 20,
};


Expand Down
11 changes: 11 additions & 0 deletions lib/media/presentation_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ shaka.media.PresentationTimeline = class {
}


/**
* Gets the presentation's segment availability duration.
*
* @return {number}
* @export
*/
getSegmentAvailabilityDuration() {
return this.segmentAvailabilityDuration_;
}


/**
* Sets the presentation delay in seconds.
*
Expand Down
23 changes: 23 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4499,6 +4499,29 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}
}

/**
* Get the presentation segment availability duration. This should only be
* called when the player has loaded a live stream. If the player has not
* loaded a live stream, this will return <code>null</code>.
*
* @return {?number}
* @export
*/
getSegmentAvailabilityDuration() {
if (!this.isLive()) {
shaka.log.warning('getSegmentAvailabilityDuration is for live streams!');
return null;
}

if (this.manifest_) {
const timeline = this.manifest_.presentationTimeline;
return timeline.getSegmentAvailabilityDuration();
} else {
shaka.log.warning('No way to get segment segment availability duration!');
return null;
}
}

/**
* Get information about what the player has buffered. If the player has not
* loaded content or is currently loading content, the buffered content will
Expand Down
26 changes: 26 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3764,6 +3764,32 @@ describe('Player', () => {
});
});

describe('getSegmentAvailabilityDuration()', () => {
beforeEach(async () => {
const timeline = new shaka.media.PresentationTimeline(300, 0);
timeline.setStatic(false);
timeline.setSegmentAvailabilityDuration(1000);

manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.presentationTimeline = timeline;
manifest.addVariant(0, (variant) => {
variant.addVideo(1);
});
});

goog.asserts.assert(manifest, 'manifest must be non-null');
await player.load(fakeManifestUri, 0, fakeMimeType);
});

it('gets current segment availability duration', () => {
playhead.getTime.and.returnValue(20);

const segmentAvailabiltyDuration =
player.getSegmentAvailabilityDuration();
expect(segmentAvailabiltyDuration).toBe(1000);
});
});

it('rejects empty manifests', async () => {
manifest = shaka.test.ManifestGenerator.generate();

Expand Down

0 comments on commit 8ff5b59

Please sign in to comment.