Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-13540): allow passing entry id to start playing the playlist from #722

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion docs/playlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ For all playlist options, see [`KPPlaylistObject`](./api.md#kpplaylistobject).

## Configure the Playlist

### StartAtEntryId

By default, a playlist starts playing from the first entry.
<br>To change this behavior, configure the [`options`](./api.md#kpplaylistoptions) under [`KPPlaylistConfigObject`](./api.md#kpplaylistconfigobject) using one of the following methods:
<br>Via the API:

```javascript
kalturaPlayer.loadPlaylist({playlistId: '123456'}, {options: {startAtEntryId: '1_xxxxxx'}});
```

```javascript
kalturaPlayer.loadPlaylistByEntryList({entries: [{entryId: '01234'}, {entryId: '56789'}]}, {options: {startAtEntryId: '1_xxxxxx'}});
```

By configuration:

```javascript
kalturaPlayer.configure({
playlist: {
options: {startAtEntryId: '1_xxxxxx'}
}
});
```

For full playlist options see [`KPPlaylistOptions`](./api.md#kpplaylistoptions).

### Auto Continue

By default, once the current item is ended, the playlist continues to the next item automatically.
Expand Down Expand Up @@ -230,4 +256,4 @@ kalturaPlayer.loadPlaylist({playlistId: '56789'}, {options: {autoContinue: true}

## Error Handling

Error handling is based on player errors which may result from Kaltura api requests or media issues
Error handling is based on player errors which may result from Kaltura api requests or media issues
19 changes: 18 additions & 1 deletion src/common/playlist/playlist-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,24 @@ class PlaylistManager {
// @ts-ignore
this._player.dispatchEvent(new FakeEvent(PlaylistEventType.PLAYLIST_LOADED, { playlist: this }));
this._addBindings();
this.playNext();
const startPlaylistAtEntryId = config.options?.startAtEntryId;
let wasEntryIdSet = false;
if (
startPlaylistAtEntryId &&
typeof startPlaylistAtEntryId === 'string'
) {
const entryToPlay: PlaylistItem | undefined =
this._playlist.items.find(
(item: PlaylistItem) => item.sources.id === startPlaylistAtEntryId
);
if (entryToPlay) {
wasEntryIdSet = true;
this.playItem(entryToPlay.index);
}
}
if (!wasEntryIdSet) {
this.playNext();
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/playlist/playlist-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* @typedef {Object} KPPlaylistOptions
* @property {boolean} [autoContinue=true] - Determines whether to continue to the next item automatically.
* @property {boolean} [loop=false] - Determines whether to play the playlist in a loop. When selected, the playlist will play automatically even if autoContinue is set to false.
* @property {string} [startAtEntryId] - Determines which entry id to start to the play the playlist from.
*/
export interface PlaylistOptions {
autoContinue: boolean;
loop: boolean;
imageDuration: number;
documentDuration: number;
startAtEntryId?: string;
}
Loading