11import clsx from 'clsx'
2- import {
3- RefObject ,
4- useCallback ,
5- useEffect ,
6- useMemo ,
7- useRef ,
8- useState ,
9- } from 'react'
2+ import { RefObject , useCallback , useEffect , useMemo , useState } from 'react'
103import { ProgressSlider } from '@/app/components/ui/slider'
114import { podcasts } from '@/service/podcasts'
12- import { subsonic } from '@/service/subsonic'
135import {
146 usePlayerActions ,
157 usePlayerDuration ,
16- usePlayerIsPlaying ,
178 usePlayerMediaType ,
189 usePlayerProgress ,
1910 usePlayerSonglist ,
@@ -31,13 +22,10 @@ export function PlayerProgress({ audioRef }: PlayerProgressProps) {
3122 const progress = usePlayerProgress ( )
3223 const [ localProgress , setLocalProgress ] = useState ( progress )
3324 const currentDuration = usePlayerDuration ( )
34- const isPlaying = usePlayerIsPlaying ( )
35- const { currentSong, currentList, podcastList, currentSongIndex } =
36- usePlayerSonglist ( )
25+ const { currentList, podcastList, currentSongIndex } = usePlayerSonglist ( )
3726 const { isSong, isPodcast } = usePlayerMediaType ( )
3827 const { setProgress, setUpdatePodcastProgress, getCurrentPodcastProgress } =
3928 usePlayerActions ( )
40- const isScrobbleSentRef = useRef ( false )
4129
4230 const isEmpty = isSong && currentList . length === 0
4331
@@ -77,44 +65,6 @@ export function PlayerProgress({ audioRef }: PlayerProgressProps) {
7765 [ currentDuration ] ,
7866 )
7967
80- const sendScrobble = useCallback ( async ( songId : string ) => {
81- await subsonic . scrobble . send ( songId )
82- } , [ ] )
83-
84- const progressTicks = useRef ( 0 )
85-
86- useEffect ( ( ) => {
87- if ( isSeeking || ! isPlaying ) {
88- return
89- }
90- if ( isSong ) {
91- const progressPercentage = ( progress / currentDuration ) * 100
92-
93- if ( progressPercentage === 0 ) {
94- isScrobbleSentRef . current = false
95- progressTicks . current = 0
96- } else {
97- progressTicks . current += 1
98-
99- if (
100- ( progressTicks . current >= currentDuration / 2 ||
101- progressTicks . current >= 60 * 4 ) &&
102- ! isScrobbleSentRef . current
103- ) {
104- sendScrobble ( currentSong . id )
105- isScrobbleSentRef . current = true
106- }
107- }
108- }
109- } , [
110- progress ,
111- currentDuration ,
112- isSong ,
113- sendScrobble ,
114- currentSong . id ,
115- isPlaying ,
116- ] )
117-
11868 // Used to save listening progress to backend every 30 seconds
11969 useEffect ( ( ) => {
12070 if ( ! isPodcast || ! podcastList ) return
0 commit comments