mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-12-19 05:36:30 +00:00
Merge pull request #37 from fly-apps/mc-media-session
Add now playing info
This commit is contained in:
commit
d25554632f
2 changed files with 13 additions and 3 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())
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue