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

Media Session API: Add artwork #162

Merged
merged 9 commits into from
Oct 5, 2021
Merged

Conversation

dero
Copy link
Collaborator

@dero dero commented Sep 29, 2021

Summary

When mediaSession.metadata is set, the app now uses artwork specific to the currently playing video. The video specific artwork is also cached by the SW.

Fixes #161

image

@dero dero requested a review from derekherman September 29, 2021 14:51
@@ -69,6 +69,9 @@ export default function generateCache() {
} else if (Object.prototype.toString.call(video.thumbnail) === '[object String]') {
assetsToCache.push(video.thumbnail);
}
if (Array.isArray(video['media-session-artwork'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed to cache media session artwork images if the Media Session API is not supported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beaufortfrancois I was wondering if we even want to cache those files. It's quite a lot of data – 400 kB currently – and the benefit of the artwork being available in the offline mode is marginal IMO. We can always fall back to the default artwork in those cases.

And if you're asking whether we should exclude browsers with no Media Session API support, then I'd say perhaps. With Safari 15 on iOS out the door, there is currently no mainstream evergreen browser that would not support it.

image

What is your opinion on the caching?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your opinion on the caching?

Is it possible to cache them only when media session metadata are set?
In other words, only when the media starts playing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding logic to the SW to cache this artwork when it's played, or dowloaded for offline playback, would be a better user experience instead of caching all the artwork during initialization.

Copy link
Collaborator Author

@dero dero Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, guys, thank you. I've implemented the changes in d7ac820

The artwork is now cached when a video is played or downloaded.

@beaufortfrancois @derekherman Can you please take another look?

Copy link
Member

@beaufortfrancois beaufortfrancois Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: Is this caching assets every time video is played and/or downloaded or only once?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beaufortfrancois Aha, good point, I did not realize cache.addAll would overwrite the cache entries. Updated the saveToCache implementation in 64ca172. Could you please take a look?

I believe it is sufficient to match the URL, because we're versioning cache. LMK if you think this needs to be more robust. Thanks!

@@ -9,6 +9,26 @@ video-sources:
- src: https://storage.googleapis.com/kino-assets/single-video/video.mp4
type: video/mp4; codecs="avc1.640032,mp4a.40.2"
thumbnail: https://storage.googleapis.com/kino-assets/single-video/thumbnail.png
media-session-artwork:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we already have linter warnings so that we don't forget to add media session artwork to future .md files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how that would be useful, but I don't believe I've ever linted front-matter blocks in markdown files. What tool would you recommend for the task?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a markdown linter is a great idea. However, it feels a bit out of scope for this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Do you mind filing a feature request to keep track of it?

Copy link
Member

@beaufortfrancois beaufortfrancois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -9,6 +9,26 @@ video-sources:
- src: https://storage.googleapis.com/kino-assets/single-video/video.mp4
type: video/mp4; codecs="avc1.640032,mp4a.40.2"
thumbnail: https://storage.googleapis.com/kino-assets/single-video/thumbnail.png
media-session-artwork:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Do you mind filing a feature request to keep track of it?

* @returns {string[]} URLs.
*/
getMediaSessionArtworkUrls() {
const artworkObjects = this.internal.videoData['media-session-artwork'] || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have default artwork URL there as a fallback or is it safe to assume MEDIA_SESSION_DEFAULT_ARTWORK will always be in the cache?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beaufortfrancois You're right, we should have the default artwork pulled in here. Updated the implementation in ab8c104.

@derekherman derekherman merged commit df74c7d into develop Oct 5, 2021
@derekherman derekherman deleted the update/media-session-images branch October 5, 2021 05:50
@felipebochehin87
Copy link

Tested against https://kinoweb-dev--staging-2ra3ji0i.web.app/

  1. Added Media Session to the browser
  2. Opened https://kinoweb-dev--staging-2ra3ji0i.web.app/
  3. Clicked on a video
  4. Played the video
  5. Opened Media Session - video info is displayed exactly as the video that is being played ✔️

Kino 162

Kino 162  2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display video artwork in the Media Session API
4 participants