diff --git a/assets/js/app.js b/assets/js/app.js index 476cdc1..bc622f0 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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()) diff --git a/lib/live_beats_web/live/player_live.ex b/lib/live_beats_web/live/player_live.ex index 26bc162..aba490c 100644 --- a/lib/live_beats_web/live/player_live.ex +++ b/lib/live_beats_web/live/player_live.ex @@ -276,13 +276,17 @@ defmodule LiveBeatsWeb.PlayerLive do defp play_song(socket, %Song{} = song, elapsed) do socket |> push_play(song, elapsed) - |> assign(song: song, playing: true) + |> assign(song: song, playing: true, page_title: song_title(song)) end defp stop_song(socket) do socket |> push_event("stop", %{}) - |> assign(song: nil, playing: false) + |> assign(song: nil, playing: false, page_title: "Listing Songs") + end + + defp song_title(%{artist: artist, title: title}) do + "#{title} - #{artist} (Now Playing)" end defp play_current_song(socket) do @@ -310,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,