Search code examples
javascripthtmlwindowshtml5-videomediasession

How to set the HTML video title that is shown in Chrome and Windows?


How can I set the name (label) of HTML5 <video> element that browsers (like Chrome) and Windows OS display?

Like the title that Windows shows for this youtube video (when changing speaker volume):

enter image description here

Currently for me the page title is shown (the title set in page head).
I tried adding a title="..." attribute to the video element but it had no effect. Also didn't find a solution on StackOverflow.


Solution

  • As the other answer stated, it can be done with JavaScript and Media Session API.
    Check out this YouTube video.

    if ("mediaSession" in navigator) {
      navigator.mediaSession.metadata = new MediaMetadata({
        title: "Unforgettable",
        artist: "Nat King Cole",
        album: "The Ultimate Collection (Remastered)",
        artwork: [
          { src: "https://dummyimage.com/128x128", sizes: "128x128", type: "image/png" },
          { src: "https://dummyimage.com/512x512", sizes: "512x512", type: "image/png" }
        ]
      });
    }