mirror of
https://github.com/Jellify-Music/App.git
synced 2026-03-17 10:40:38 -05:00
use total duration from track metadata
This commit is contained in:
@@ -7,7 +7,8 @@ import {
|
||||
useNowPlaying,
|
||||
useOnPlaybackStateChange,
|
||||
} from 'react-native-nitro-player'
|
||||
import { usePlaybackPosition, useTotalDuration } from '../../stores/player/playback'
|
||||
import { usePlaybackPosition } from '../../stores/player/playback'
|
||||
import { useCurrentTrack } from '../../stores/player/queue'
|
||||
|
||||
interface UseProgressResult {
|
||||
position: number
|
||||
@@ -16,7 +17,7 @@ interface UseProgressResult {
|
||||
|
||||
export const useProgress = (): UseProgressResult => {
|
||||
const position = usePlaybackPosition()
|
||||
const totalDuration = useTotalDuration()
|
||||
const totalDuration = useCurrentTrack()?.duration || 0
|
||||
|
||||
const playerEngineData = usePlayerEngineStore((state) => state.playerEngineData)
|
||||
|
||||
|
||||
@@ -105,7 +105,6 @@ export async function onChangeTrack() {
|
||||
export async function onPlaybackProgress(position: number, totalDuration: number) {
|
||||
usePlayerPlaybackStore.setState({
|
||||
position,
|
||||
totalDuration,
|
||||
})
|
||||
|
||||
const { currentTrack } = usePlayerQueueStore.getState()
|
||||
|
||||
@@ -5,9 +5,6 @@ import { devtools, persist, createJSONStorage } from 'zustand/middleware'
|
||||
type PlayerPlaybackStore = {
|
||||
position: number
|
||||
setPosition: (position: number) => void
|
||||
|
||||
totalDuration: number
|
||||
setTotalDuration: (duration: number) => void
|
||||
}
|
||||
|
||||
export const usePlayerPlaybackStore = create<PlayerPlaybackStore>()(
|
||||
@@ -16,9 +13,6 @@ export const usePlayerPlaybackStore = create<PlayerPlaybackStore>()(
|
||||
(set) => ({
|
||||
position: 0,
|
||||
setPosition: (position: number) => set({ position }),
|
||||
|
||||
totalDuration: 0,
|
||||
setTotalDuration: (duration: number) => set({ totalDuration: duration }),
|
||||
}),
|
||||
{
|
||||
name: 'player-playback-storage',
|
||||
@@ -33,9 +27,3 @@ export const usePlaybackPosition = () => usePlayerPlaybackStore((state) => state
|
||||
export const setPlaybackPosition = (position: number) => {
|
||||
usePlayerPlaybackStore.getState().setPosition(position)
|
||||
}
|
||||
|
||||
export const useTotalDuration = () => usePlayerPlaybackStore((state) => state.totalDuration)
|
||||
|
||||
export const setTotalDuration = (duration: number) => {
|
||||
usePlayerPlaybackStore.getState().setTotalDuration(duration)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user