Skip to content

Commit

Permalink
feat(FEC-13871): set the entry name to navigator media metadata (#765)
Browse files Browse the repository at this point in the history
### Description of the Changes

when playing a media on a mobile device and exiting the browser- the
request is for the mobile device to show the entry name of the media
that is played and the thumbnail as the background, in the native device
player.

- using `MediaMetadata` object to pass to the `navigator.mediaSession`
- configuring the navigator `mediaSession` in `setMedia` to cover
playlist and setMedia use-cases
- in case there is not entry name or poster, resetting to empty string
so it will not show the previews information

#### Resolves FEC-13871
  • Loading branch information
lianbenjamin authored Apr 17, 2024
1 parent 04b0ce8 commit 579566d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/kaltura-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class KalturaPlayer extends FakeEventTarget {
playerConfig.playback = playback;
}
this.configure({ ...playerConfig, sources });
this._configureInformationForDevice(mediaConfig);
}

public async loadPlaylist(playlistInfo: ProviderPlaylistInfoObject, playlistConfig: PlaylistConfigObject): Promise<ProviderPlaylistObject> {
Expand Down Expand Up @@ -823,6 +824,29 @@ export class KalturaPlayer extends FakeEventTarget {
return this._localPlayer.Error;
}

private _configureInformationForDevice(mediaConfig: KPMediaConfig): void {
// here we can provide information about the media, to a device that is playing it
// set the media metadata title to the name of the entry, if exists
// set the media thumbnail to appear as the background of a native device's player, if exists
const getMediaThumbnail = (poster: any): string => {
if (typeof poster === 'string') {
return poster;
}
if (Array.isArray(poster) && poster.length > 0) {
return poster[0];
}
return '';
};

if (navigator.mediaSession) {
const mediaThumbnail = getMediaThumbnail(mediaConfig.sources.poster);
navigator.mediaSession.metadata = new MediaMetadata({
title: mediaConfig.sources.metadata?.name || '',
artwork: mediaThumbnail ? [{ src: mediaThumbnail }] : []
});
}
}

private _addBindings(): void {
this._eventManager.listen(this, CoreEventType.CHANGE_SOURCE_STARTED, () => this._onChangeSourceStarted());
this._eventManager.listen(this, CoreEventType.CHANGE_SOURCE_ENDED, () => this._onChangeSourceEnded());
Expand Down

0 comments on commit 579566d

Please sign in to comment.