Show indicator on current playing song. Fixes #128

This commit is contained in:
Deluan
2020-06-13 13:44:01 -04:00
parent f8a18b59b0
commit be2afb94ae
8 changed files with 102 additions and 31 deletions
+7 -8
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, progress } from './queue'
import themes from '../themes'
import { makeStyles } from '@material-ui/core/styles'
@@ -100,8 +100,12 @@ const Player = () => {
}
const OnAudioProgress = (info) => {
const progress = (info.currentTime / info.duration) * 100
if (isNaN(info.duration) || progress < 90) {
if (info.ended) {
document.title = 'Navidrome'
}
dispatch(progress(info))
const pos = (info.currentTime / info.duration) * 100
if (isNaN(info.duration) || pos < 90) {
return
}
const item = queue.queue.find((item) => item.trackId === info.trackId)
@@ -120,10 +124,6 @@ const Player = () => {
}
}
const onAudioEnded = () => {
document.title = 'Navidrome'
}
if (authenticated && options.audioLists.length > 0) {
return (
<ReactJkMusicPlayer
@@ -131,7 +131,6 @@ const Player = () => {
onAudioListsChange={OnAudioListsChange}
onAudioProgress={OnAudioProgress}
onAudioPlay={OnAudioPlay}
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_PROGRESS = 'PLAYER_PROGRESS'
const mapToAudioLists = (item) => {
// If item comes from a playlist, id is mediaFileId
@@ -88,13 +89,30 @@ const scrobble = (id, submit) => ({
submit,
})
const progress = (audioInfo) => ({
type: PLAYER_PROGRESS,
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_PROGRESS:
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,
progress,
shuffleTracks,
playQueueReducer,
}