w3c / mediasession

Media Session API
https://w3c.github.io/mediasession/
Other
128 stars 30 forks source link

Why is MediaMetadata nullable? #239

Open ChunMinChang opened 5 years ago

ChunMinChang commented 5 years ago

The update metadata algorithm doesn't handle the null MediaMetadata value. If MediaMetadata can be nullable, the spec should state the null value handling in the algorithm.

There are two places in the spec mentioning the null metadata. One is the definition of the empty-metadata, the other is MediaSession interface. It seems to me that the null metadata is just used to reset the platform UI to a default view. In that case, I guess the empty metadata will do the same job. If that's the only reason the metadata can be null, is it possible to use empty metadata instead? If there is another reason to make the metadata nullable, could update metadata algorithm add some steps to handle the null metadata?

The definition of the empty-metadata

A MediaMetadata is said to be an empty metadata if it is equal to null or all the following conditions are true:

  • Its title is the empty string.
  • Its artist is the empty string.
  • Its album is the empty string.
  • Its artwork images length is 0.

MediaSession interface

The metadata attribute reflects the MediaSession's metadata. On getting, it MUST return the MediaSession's metadata. On setting, it MUST run the following steps with value being the new value being set:

  1. If the MediaSession's metadata is not null, set its media session to null.
  2. Set the MediaSession's metadata to value.
  3. If the MediaSession's metadata is not null, set its media session to the current MediaSession.
  4. In parallel, run the update metadata algorithm.
youennf commented 1 year ago

If there is another reason to make the metadata nullable, could update metadata algorithm add some steps to handle the null metadata?

I think it is handy to reset the UI by setting null. It would indeed be good to update https://w3c.github.io/mediasession/#update-metadata-algorithm to handle the null case. Marking as ready for PR.