send "Now Playing" scrobble to server on beginning new track
This commit is contained in:
@@ -55,6 +55,7 @@ func NewPlaybackManager(ctx context.Context, s *ServerManager, p *player.Player)
|
|||||||
pm.curTrackTime = float64(pm.playQueue[pm.nowPlayingIdx].Duration)
|
pm.curTrackTime = float64(pm.playQueue[pm.nowPlayingIdx].Duration)
|
||||||
pm.invokeOnSongChangeCallbacks()
|
pm.invokeOnSongChangeCallbacks()
|
||||||
pm.doUpdateTimePos()
|
pm.doUpdateTimePos()
|
||||||
|
pm.sendNowPlayingScrobble()
|
||||||
})
|
})
|
||||||
p.OnSeek(func() {
|
p.OnSeek(func() {
|
||||||
pm.doUpdateTimePos()
|
pm.doUpdateTimePos()
|
||||||
@@ -258,6 +259,7 @@ func (p *PlaybackManager) StopAndClearPlayQueue() {
|
|||||||
p.playQueue = nil
|
p.playQueue = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// call BEFORE updating p.nowPlayingIdx
|
||||||
func (p *PlaybackManager) checkScrobble(playDur time.Duration) {
|
func (p *PlaybackManager) checkScrobble(playDur time.Duration) {
|
||||||
if len(p.playQueue) == 0 || p.nowPlayingIdx < 0 {
|
if len(p.playQueue) == 0 || p.nowPlayingIdx < 0 {
|
||||||
return
|
return
|
||||||
@@ -270,10 +272,21 @@ func (p *PlaybackManager) checkScrobble(playDur time.Duration) {
|
|||||||
log.Printf("Scrobbling %q", song.Title)
|
log.Printf("Scrobbling %q", song.Title)
|
||||||
song.PlayCount += 1
|
song.PlayCount += 1
|
||||||
p.lastScrobbled = song
|
p.lastScrobbled = song
|
||||||
p.sm.Server.Scrobble(song.ID, map[string]string{"time": strconv.FormatInt(time.Now().Unix()*1000, 10)})
|
go p.sm.Server.Scrobble(song.ID, map[string]string{"time": strconv.FormatInt(time.Now().Unix()*1000, 10)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PlaybackManager) sendNowPlayingScrobble() {
|
||||||
|
if len(p.playQueue) == 0 || p.nowPlayingIdx < 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
song := p.playQueue[p.nowPlayingIdx]
|
||||||
|
go p.sm.Server.Scrobble(song.ID, map[string]string{
|
||||||
|
"time": strconv.FormatInt(time.Now().Unix()*1000, 10),
|
||||||
|
"submission": "false",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PlaybackManager) invokeOnSongChangeCallbacks() {
|
func (p *PlaybackManager) invokeOnSongChangeCallbacks() {
|
||||||
for _, cb := range p.onSongChange {
|
for _, cb := range p.onSongChange {
|
||||||
cb(p.NowPlaying(), p.lastScrobbled)
|
cb(p.NowPlaying(), p.lastScrobbled)
|
||||||
|
|||||||
Reference in New Issue
Block a user