Add MediaMetadata to audio player when available

This commit is contained in:
Michael Crumm 2022-02-03 09:46:19 -08:00
parent 7ef57e8813
commit 645c4bd117
No known key found for this signature in database
GPG key ID: 4BE92DCED9E69BAA
2 changed files with 7 additions and 1 deletions

View file

@ -116,7 +116,7 @@ Hooks.AudioPlayer = {
this.play()
}
})
this.handleEvent("play", ({url, token, elapsed}) => {
this.handleEvent("play", ({url, token, elapsed, artist, title}) => {
this.playbackBeganAt = nowSeconds() - elapsed
let currentSrc = this.player.src.split("?")[0]
if(currentSrc === url && this.player.paused){
@ -125,6 +125,10 @@ Hooks.AudioPlayer = {
this.player.src = `${url}?token=${token}`
this.play({sync: true})
}
if("mediaSession" in navigator){
navigator.mediaSession.metadata = new MediaMetadata({artist, title})
}
})
this.handleEvent("pause", () => this.pause())
this.handleEvent("stop", () => this.stop())

View file

@ -314,6 +314,8 @@ defmodule LiveBeatsWeb.PlayerLive do
})
push_event(socket, "play", %{
artist: song.artist,
title: song.title,
paused: Song.paused?(song),
elapsed: elapsed,
duration: song.duration,