From db1d277fed793659e4a20354e6588d78612a47f6 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:16:23 +0300 Subject: [PATCH 1/8] feat(FEC-13871): set the entry name to navigator media metadata --- src/kaltura-player.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index edcfbe495..4a11c42da 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -169,6 +169,7 @@ export class KalturaPlayer extends FakeEventTarget { this._appPluginConfig = mergedPluginsConfigAndFromApp[1]; this.configure(getDefaultRedirectOptions({ sources: this.sources }, mediaConfig)); this.setMedia(mediaConfig); + this._configureMediaMetadata(mediaConfig); return mediaConfig; } catch (e) { const category = getErrorCategory(e); @@ -823,6 +824,12 @@ export class KalturaPlayer extends FakeEventTarget { return this._localPlayer.Error; } + private _configureMediaMetadata(mediaConfig: ProviderMediaConfigObject): 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 + navigator.mediaSession.metadata = new MediaMetadata({title: mediaConfig.sources.metadata.name}); + } + private _addBindings(): void { this._eventManager.listen(this, CoreEventType.CHANGE_SOURCE_STARTED, () => this._onChangeSourceStarted()); this._eventManager.listen(this, CoreEventType.CHANGE_SOURCE_ENDED, () => this._onChangeSourceEnded()); From ee7a6147f4c32c59c8f42fd791c2b38645678d98 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:21:14 +0300 Subject: [PATCH 2/8] fix lint --- src/kaltura-player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index 4a11c42da..77fe796e9 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -827,7 +827,7 @@ export class KalturaPlayer extends FakeEventTarget { private _configureMediaMetadata(mediaConfig: ProviderMediaConfigObject): 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 - navigator.mediaSession.metadata = new MediaMetadata({title: mediaConfig.sources.metadata.name}); + navigator.mediaSession.metadata = new MediaMetadata({ title: mediaConfig.sources.metadata.name }); } private _addBindings(): void { From cd965b898f7804c9ad8c66b38d28d1135251e16e Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:14:48 +0300 Subject: [PATCH 3/8] make sure mediaSession exists on navigator --- src/kaltura-player.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index 77fe796e9..b2450359a 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -827,7 +827,9 @@ export class KalturaPlayer extends FakeEventTarget { private _configureMediaMetadata(mediaConfig: ProviderMediaConfigObject): 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 - navigator.mediaSession.metadata = new MediaMetadata({ title: mediaConfig.sources.metadata.name }); + if (navigator.mediaSession) { + navigator.mediaSession.metadata = new MediaMetadata({ title: mediaConfig.sources.metadata.name }); + } } private _addBindings(): void { From ad0af39eaf35958c6bee6ec597b68477b86f770f Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:06:46 +0300 Subject: [PATCH 4/8] move to setMedia to support playlist --- src/kaltura-player.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index b2450359a..8452fa8da 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -169,7 +169,6 @@ export class KalturaPlayer extends FakeEventTarget { this._appPluginConfig = mergedPluginsConfigAndFromApp[1]; this.configure(getDefaultRedirectOptions({ sources: this.sources }, mediaConfig)); this.setMedia(mediaConfig); - this._configureMediaMetadata(mediaConfig); return mediaConfig; } catch (e) { const category = getErrorCategory(e); @@ -207,6 +206,7 @@ export class KalturaPlayer extends FakeEventTarget { playerConfig.playback = playback; } this.configure({ ...playerConfig, sources }); + this._configureMediaMetadata(mediaConfig); } public async loadPlaylist(playlistInfo: ProviderPlaylistInfoObject, playlistConfig: PlaylistConfigObject): Promise { @@ -824,7 +824,7 @@ export class KalturaPlayer extends FakeEventTarget { return this._localPlayer.Error; } - private _configureMediaMetadata(mediaConfig: ProviderMediaConfigObject): void { + private _configureMediaMetadata(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 (navigator.mediaSession) { From 92f7c20f2667a83ae49e7add92553cc5184657d7 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:20:24 +0300 Subject: [PATCH 5/8] fix tests failure --- src/kaltura-player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index 8452fa8da..ef829adfd 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -828,7 +828,7 @@ export class KalturaPlayer extends FakeEventTarget { // 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 (navigator.mediaSession) { - navigator.mediaSession.metadata = new MediaMetadata({ title: mediaConfig.sources.metadata.name }); + navigator.mediaSession.metadata = new MediaMetadata({ title: mediaConfig.sources.metadata?.name }); } } From 4a22802147137929161849d4558579704ba7dc7e Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:33:07 +0300 Subject: [PATCH 6/8] reset the metadata if there name of media was not provided --- src/kaltura-player.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index ef829adfd..a16ab0fd2 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -826,9 +826,12 @@ export class KalturaPlayer extends FakeEventTarget { private _configureMediaMetadata(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 (navigator.mediaSession) { - navigator.mediaSession.metadata = new MediaMetadata({ title: mediaConfig.sources.metadata?.name }); + // set the media metadata title to the name of the entry, if exists + const mediaName = mediaConfig.sources.metadata?.name; + if (navigator.mediaSession && mediaName) { + navigator.mediaSession.metadata = new MediaMetadata({ title: mediaName }); + } else if (navigator.mediaSession?.metadata) { + navigator.mediaSession.metadata = null; } } From fb8969498ff056ed854de62f5df1d36e90e12bf4 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:49:47 +0300 Subject: [PATCH 7/8] set also the thumbnail of the video and address pr comments --- src/kaltura-player.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index a16ab0fd2..0ee224fc6 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -206,7 +206,7 @@ export class KalturaPlayer extends FakeEventTarget { playerConfig.playback = playback; } this.configure({ ...playerConfig, sources }); - this._configureMediaMetadata(mediaConfig); + this._configureInformationForDevice(mediaConfig); } public async loadPlaylist(playlistInfo: ProviderPlaylistInfoObject, playlistConfig: PlaylistConfigObject): Promise { @@ -824,14 +824,26 @@ export class KalturaPlayer extends FakeEventTarget { return this._localPlayer.Error; } - private _configureMediaMetadata(mediaConfig: KPMediaConfig): void { + 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 - const mediaName = mediaConfig.sources.metadata?.name; - if (navigator.mediaSession && mediaName) { - navigator.mediaSession.metadata = new MediaMetadata({ title: mediaName }); - } else if (navigator.mediaSession?.metadata) { - navigator.mediaSession.metadata = null; + // 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 >= 1) { + 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 }] : [] + }); } } From 26e610c89142d6db3ee75f0ac09e47db35220d20 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:17:03 +0300 Subject: [PATCH 8/8] small fix --- src/kaltura-player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaltura-player.ts b/src/kaltura-player.ts index 0ee224fc6..0743787ff 100644 --- a/src/kaltura-player.ts +++ b/src/kaltura-player.ts @@ -832,7 +832,7 @@ export class KalturaPlayer extends FakeEventTarget { if (typeof poster === 'string') { return poster; } - if (Array.isArray(poster) && poster.length >= 1) { + if (Array.isArray(poster) && poster.length > 0) { return poster[0]; } return '';