start adding payment
This commit is contained in:
@@ -84,6 +84,7 @@ const DEFAULT_CONTEXT = {
|
||||
isLooping: false,
|
||||
setLooping: noop,
|
||||
toggleLooping: noop,
|
||||
getTrackInfo: () => null,
|
||||
};
|
||||
|
||||
export const PlayerContext = createContext(DEFAULT_CONTEXT);
|
||||
@@ -230,6 +231,7 @@ const PlayerProvider = ({ children }) => {
|
||||
const autoPlayRef = useRef(false);
|
||||
const pendingSeekValueRef = useRef(null);
|
||||
const didJustFinishRef = useRef(false);
|
||||
const trackInfoRef = useRef({});
|
||||
|
||||
const setQueueIndexValue = useCallback((index = -1) => {
|
||||
const list = queueRef.current;
|
||||
@@ -401,6 +403,18 @@ const PlayerProvider = ({ children }) => {
|
||||
durationMs,
|
||||
};
|
||||
});
|
||||
|
||||
if (currentTrack?.id) {
|
||||
trackInfoRef.current[currentTrack.id] = {
|
||||
durationMs:
|
||||
durationMs > 0
|
||||
? durationMs
|
||||
: trackInfoRef.current[currentTrack.id]?.durationMs || 0,
|
||||
positionMs,
|
||||
isLoaded,
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
}
|
||||
}, [status, currentTrack]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -614,6 +628,10 @@ const PlayerProvider = ({ children }) => {
|
||||
const toggleLooping = useCallback(() => {
|
||||
setIsLooping((prev) => !prev);
|
||||
}, []);
|
||||
const getTrackInfo = useCallback((trackId) => {
|
||||
if (!trackId) return null;
|
||||
return trackInfoRef.current[trackId] || null;
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentTrack?.id) {
|
||||
@@ -692,6 +710,7 @@ const PlayerProvider = ({ children }) => {
|
||||
isLooping,
|
||||
setLooping,
|
||||
toggleLooping,
|
||||
getTrackInfo,
|
||||
}),
|
||||
[
|
||||
currentTrack,
|
||||
@@ -715,6 +734,7 @@ const PlayerProvider = ({ children }) => {
|
||||
setLooping,
|
||||
toggleLooping,
|
||||
setQueue,
|
||||
getTrackInfo,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user