В современных браузерах работает такой код:
async function Mediasessionnew()
{
if (arguments[0] == "Off")
{
navigator.mediaSession.metadata = new MediaMetadata(
{
title: "",
artist: "",
artwork: []
});
navigator.mediaSession.setActionHandler("seekto", null);
navigator.mediaSession.setActionHandler("seekbackward", null);
navigator.mediaSession.setActionHandler("seekforward", null);
navigator.mediaSession.setActionHandler("previoustrack", null);
navigator.mediaSession.setActionHandler("nexttrack", null);
navigator.mediaSession.setActionHandler("play", () => {});
navigator.mediaSession.setActionHandler("pause", () => {});
}
else
{
if (document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1] == "")
{
if (document.URL.includes("http") || document.querySelector("video").src.includes("blob:"))
{
await Prevfromcadr();
}
}
navigator.mediaSession.metadata = new MediaMetadata(
{
title: document.getElementById("SelectFile").selectedIndex + "/" + (document.getElementById("SelectFile").length - 1) + ". " + document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].value,
artist: document.getElementById("SelectPlist").selectedIndex + "/" + (document.getElementById("SelectPlist").length - 1) + ". " + document.getElementById("SelectPlist")[document.getElementById("SelectPlist").selectedIndex].value,
artwork:
[
{
src: document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1],
sizes: "96x96",
type: "image/png",
},
{
src: document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1],
sizes: "128x128",
type: "image/png",
},
{
src: document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1],
sizes: "192x192",
type: "image/png",
},
{
src: document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1],
sizes: "256x256",
type: "image/png",
},
{
src: document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1],
sizes: "384x384",
type: "image/png",
},
{
src: document.getElementById("SelectFile")[document.getElementById("SelectFile").selectedIndex].id.split("±")[1],
sizes: "512x512",
type: "image/png",
}
]
});
navigator.mediaSession.setActionHandler("seekto", (e) =>
{
document.getElementById("InputTime").value = e.seekTime;
document.getElementById("InputTime").dispatchEvent(new Event("input"));//#InputTimeInput();
});
navigator.mediaSession.setActionHandler("seekbackward", () =>
{
document.getElementById("InputTime").value = document.querySelector("video").currentTime - 5;
document.getElementById("InputTime").dispatchEvent(new Event("input"));//#InputTimeInput();
});
navigator.mediaSession.setActionHandler("seekforward", () =>
{
document.getElementById("InputTime").value = document.querySelector("video").currentTime + 5;
document.getElementById("InputTime").dispatchEvent(new Event("input"));//#InputTimeInput();
});
navigator.mediaSession.setActionHandler("previoustrack", () =>
{
document.getElementById("ButtonBack").dispatchEvent(new Event("click"));//#ButtonBackClick();
});
navigator.mediaSession.setActionHandler("nexttrack", () =>
{
document.getElementById("ButtonNext").dispatchEvent(new Event("click"));//#ButtonNextClick();
});
navigator.mediaSession.setActionHandler("play", () =>
{
document.querySelector("video").play();
});
navigator.mediaSession.setActionHandler("pause", () =>
{
document.querySelector("video").pause();
});
}
}
В старых же браузерах код выше не сработает. Есть альтернатива Media Session API? Может полифил есть? Нужно, чтобы было выглядело примерно так: