Show indicator on current playing song. Fixes #128

This commit is contained in:
Deluan
2020-06-19 09:12:45 -04:00
parent eb4c0f0b84
commit 9d23b191b5
11 changed files with 129 additions and 27 deletions
+13 -4
View File
@@ -5,7 +5,7 @@ import { useAuthState, useDataProvider, useTranslate } from 'react-admin'
import ReactJkMusicPlayer from 'react-jinke-music-player'
import 'react-jinke-music-player/assets/index.css'
import subsonic from '../subsonic'
import { scrobble, syncQueue } from './queue'
import { scrobble, syncQueue, currentPlaying } from './queue'
import themes from '../themes'
import { makeStyles } from '@material-ui/core/styles'
@@ -100,6 +100,9 @@ const Player = () => {
}
const OnAudioProgress = (info) => {
if (info.ended) {
document.title = 'Navidrome'
}
const progress = (info.currentTime / info.duration) * 100
if (isNaN(info.duration) || progress < 90) {
return
@@ -112,16 +115,21 @@ const Player = () => {
}
const OnAudioPlay = (info) => {
dispatch(currentPlaying(info))
if (info.duration) {
document.title = `${info.name} - ${info.singer} - Navidrome`
dispatch(scrobble(info.trackId, false))
subsonic.scrobble(info.trackId, false)
dataProvider.getOne('keepalive', { id: info.trackId })
}
}
const onAudioEnded = () => {
document.title = 'Navidrome'
const onAudioPause = (info) => {
dispatch(currentPlaying(info))
}
const onAudioEnded = (currentPlayId, audioLists, info) => {
dispatch(currentPlaying(info))
dataProvider.getOne('keepalive', { id: info.trackId })
}
if (authenticated && options.audioLists.length > 0) {
@@ -131,6 +139,7 @@ const Player = () => {
onAudioListsChange={OnAudioListsChange}
onAudioProgress={OnAudioProgress}
onAudioPlay={OnAudioPlay}
onAudioPause={onAudioPause}
onAudioEnded={onAudioEnded}
/>
)
+23 -2
View File
@@ -6,6 +6,7 @@ const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
const PLAYER_PLAY_TRACKS = 'PLAYER_PLAY_TRACKS'
const PLAYER_CURRENT = 'PLAYER_CURRENT'
const mapToAudioLists = (item) => {
// If item comes from a playlist, id is mediaFileId
@@ -88,13 +89,30 @@ const scrobble = (id, submit) => ({
submit,
})
const currentPlaying = (audioInfo) => ({
type: PLAYER_CURRENT,
data: audioInfo,
})
const playQueueReducer = (
previousState = { queue: [], clear: true, playing: false },
previousState = { queue: [], clear: true, playing: false, current: {} },
payload
) => {
let queue
let queue, current
const { type, data } = payload
switch (type) {
case PLAYER_CURRENT:
queue = previousState.queue
current = data.ended
? {}
: {
trackId: data.trackId,
paused: data.paused,
}
return {
...previousState,
current,
}
case PLAYER_ADD_TRACKS:
queue = previousState.queue
Object.keys(data).forEach((id) => {
@@ -109,10 +127,12 @@ const playQueueReducer = (
playing: true,
}
case PLAYER_SYNC_QUEUE:
current = data.length > 0 ? previousState.current : {}
return {
...previousState,
queue: data,
clear: false,
current,
}
case PLAYER_SCROBBLE:
const newQueue = previousState.queue.map((item) => {
@@ -156,6 +176,7 @@ export {
playTracks,
syncQueue,
scrobble,
currentPlaying,
shuffleTracks,
playQueueReducer,
}