Skip to content

Commit

Permalink
fix: Apply playRange config to src= (#7168)
Browse files Browse the repository at this point in the history
Fixes #7135
  • Loading branch information
avelad authored Aug 20, 2024
1 parent efac129 commit 7cf332e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2944,8 +2944,21 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

// By setting |src| we are done "loading" with src=. We don't need to set
// the current time because |playhead| will do that for us.
mediaElement.src = this.cmcdManager_.appendSrcData(
this.assetUri_, mimeType);
let playbackUri = this.cmcdManager_.appendSrcData(this.assetUri_, mimeType);
// Apply temporal clipping using playRangeStart and playRangeEnd based
// in https://www.w3.org/TR/media-frags/
if (!playbackUri.includes('#t=') &&
(this.config_.playRangeStart > 0 ||
isFinite(this.config_.playRangeEnd))) {
playbackUri += '#t=';
if (this.config_.playRangeStart > 0) {
playbackUri += this.config_.playRangeStart;
}
if (isFinite(this.config_.playRangeEnd)) {
playbackUri += ',' + this.config_.playRangeEnd;
}
}
mediaElement.src = playbackUri;

// Tizen 3 / WebOS won't load anything unless you call load() explicitly,
// no matter the value of the preload attribute. This is harmful on some
Expand Down
17 changes: 17 additions & 0 deletions test/player_src_equals_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,23 @@ describe('Player Src Equals', () => {
expect(player.getTextTracks()).toEqual([]);
});

it('configures play and seek range for VOD with start', async () => {
player.configure({playRangeStart: 3});
await loadWithSrcEquals(SMALL_MP4_CONTENT_URI, /* startTime= */ null);
expect(video.src.includes('#t=3')).toBeTruthy();
});

it('configures play and seek range for VOD with end', async () => {
player.configure({playRangeEnd: 8});
await loadWithSrcEquals(SMALL_MP4_CONTENT_URI, /* startTime= */ null);
expect(video.src.includes('#t=,8')).toBeTruthy();
});

it('configures play and seek range for VOD with start and end', async () => {
player.configure({playRangeStart: 3, playRangeEnd: 8});
await loadWithSrcEquals(SMALL_MP4_CONTENT_URI, /* startTime= */ null);
expect(video.src.includes('#t=3,8')).toBeTruthy();
});

// TODO: test HLS on platforms with native HLS
it('returns no languages or roles for simple mp4 content', async () => {
Expand Down

0 comments on commit 7cf332e

Please sign in to comment.