mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-05-18 09:12:41 +00:00
Merge pull request #37 from fly-apps/mc-media-session
Add now playing info
This commit is contained in:
commit
d25554632f
|
@ -116,7 +116,7 @@ Hooks.AudioPlayer = {
|
||||||
this.play()
|
this.play()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.handleEvent("play", ({url, token, elapsed}) => {
|
this.handleEvent("play", ({url, token, elapsed, artist, title}) => {
|
||||||
this.playbackBeganAt = nowSeconds() - elapsed
|
this.playbackBeganAt = nowSeconds() - elapsed
|
||||||
let currentSrc = this.player.src.split("?")[0]
|
let currentSrc = this.player.src.split("?")[0]
|
||||||
if(currentSrc === url && this.player.paused){
|
if(currentSrc === url && this.player.paused){
|
||||||
|
@ -125,6 +125,10 @@ Hooks.AudioPlayer = {
|
||||||
this.player.src = `${url}?token=${token}`
|
this.player.src = `${url}?token=${token}`
|
||||||
this.play({sync: true})
|
this.play({sync: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if("mediaSession" in navigator){
|
||||||
|
navigator.mediaSession.metadata = new MediaMetadata({artist, title})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
this.handleEvent("pause", () => this.pause())
|
this.handleEvent("pause", () => this.pause())
|
||||||
this.handleEvent("stop", () => this.stop())
|
this.handleEvent("stop", () => this.stop())
|
||||||
|
|
|
@ -276,13 +276,17 @@ defmodule LiveBeatsWeb.PlayerLive do
|
||||||
defp play_song(socket, %Song{} = song, elapsed) do
|
defp play_song(socket, %Song{} = song, elapsed) do
|
||||||
socket
|
socket
|
||||||
|> push_play(song, elapsed)
|
|> push_play(song, elapsed)
|
||||||
|> assign(song: song, playing: true)
|
|> assign(song: song, playing: true, page_title: song_title(song))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp stop_song(socket) do
|
defp stop_song(socket) do
|
||||||
socket
|
socket
|
||||||
|> push_event("stop", %{})
|
|> 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
|
end
|
||||||
|
|
||||||
defp play_current_song(socket) do
|
defp play_current_song(socket) do
|
||||||
|
@ -310,6 +314,8 @@ defmodule LiveBeatsWeb.PlayerLive do
|
||||||
})
|
})
|
||||||
|
|
||||||
push_event(socket, "play", %{
|
push_event(socket, "play", %{
|
||||||
|
artist: song.artist,
|
||||||
|
title: song.title,
|
||||||
paused: Song.paused?(song),
|
paused: Song.paused?(song),
|
||||||
elapsed: elapsed,
|
elapsed: elapsed,
|
||||||
duration: song.duration,
|
duration: song.duration,
|
||||||
|
|
Loading…
Reference in a new issue