mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-12-18 21:26:31 +00:00
Add MediaMetadata to audio player when available
This commit is contained in:
parent
7ef57e8813
commit
645c4bd117
2 changed files with 7 additions and 1 deletions
|
@ -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())
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue