Only reset player scrobbled state on track change or end (#1432)
* Only reset player scrobbled state on track change or end * Only reset player start time on track change or end
This commit is contained in:
@@ -140,13 +140,14 @@ const Player = () => {
|
|||||||
const onAudioPlay = useCallback(
|
const onAudioPlay = useCallback(
|
||||||
(info) => {
|
(info) => {
|
||||||
dispatch(currentPlaying(info))
|
dispatch(currentPlaying(info))
|
||||||
setStartTime(Date.now())
|
if (startTime === null) {
|
||||||
|
setStartTime(Date.now())
|
||||||
|
}
|
||||||
if (info.duration) {
|
if (info.duration) {
|
||||||
const song = info.song
|
const song = info.song
|
||||||
document.title = `${song.title} - ${song.artist} - Navidrome`
|
document.title = `${song.title} - ${song.artist} - Navidrome`
|
||||||
subsonic.nowPlaying(info.trackId)
|
subsonic.nowPlaying(info.trackId)
|
||||||
setPreload(false)
|
setPreload(false)
|
||||||
setScrobbled(false)
|
|
||||||
if (config.gaTrackingId) {
|
if (config.gaTrackingId) {
|
||||||
ReactGA.event({
|
ReactGA.event({
|
||||||
category: 'Player',
|
category: 'Player',
|
||||||
@@ -163,9 +164,18 @@ const Player = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[dispatch, showNotifications]
|
[dispatch, showNotifications, startTime]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const onAudioPlayTrackChange = useCallback(() => {
|
||||||
|
if (scrobbled) {
|
||||||
|
setScrobbled(false)
|
||||||
|
}
|
||||||
|
if (startTime !== null) {
|
||||||
|
setStartTime(null)
|
||||||
|
}
|
||||||
|
}, [scrobbled, startTime])
|
||||||
|
|
||||||
const onAudioPause = useCallback(
|
const onAudioPause = useCallback(
|
||||||
(info) => dispatch(currentPlaying(info)),
|
(info) => dispatch(currentPlaying(info)),
|
||||||
[dispatch]
|
[dispatch]
|
||||||
@@ -173,6 +183,8 @@ const Player = () => {
|
|||||||
|
|
||||||
const onAudioEnded = useCallback(
|
const onAudioEnded = useCallback(
|
||||||
(currentPlayId, audioLists, info) => {
|
(currentPlayId, audioLists, info) => {
|
||||||
|
setScrobbled(false)
|
||||||
|
setStartTime(null)
|
||||||
dispatch(currentPlaying(info))
|
dispatch(currentPlaying(info))
|
||||||
dataProvider
|
dataProvider
|
||||||
.getOne('keepalive', { id: info.trackId })
|
.getOne('keepalive', { id: info.trackId })
|
||||||
@@ -212,6 +224,7 @@ const Player = () => {
|
|||||||
onAudioVolumeChange={onAudioVolumeChange}
|
onAudioVolumeChange={onAudioVolumeChange}
|
||||||
onAudioProgress={onAudioProgress}
|
onAudioProgress={onAudioProgress}
|
||||||
onAudioPlay={onAudioPlay}
|
onAudioPlay={onAudioPlay}
|
||||||
|
onAudioPlayTrackChange={onAudioPlayTrackChange}
|
||||||
onAudioPause={onAudioPause}
|
onAudioPause={onAudioPause}
|
||||||
onAudioEnded={onAudioEnded}
|
onAudioEnded={onAudioEnded}
|
||||||
onCoverClick={onCoverClick}
|
onCoverClick={onCoverClick}
|
||||||
|
|||||||
Reference in New Issue
Block a user