fix slider
This commit is contained in:
@@ -55,6 +55,7 @@ const MusicDetails = ({ route }) => {
|
||||
const [fav, setFav] = useState(false);
|
||||
const [currentUID] = useGlobal("currentUID");
|
||||
const wasPlayingBeforeSeek = React.useRef(false);
|
||||
const lastSeekTargetMs = React.useRef(null);
|
||||
const listenedMsRef = React.useRef(0);
|
||||
const incrementDoneRef = React.useRef(false);
|
||||
const timerRef = React.useRef(null);
|
||||
@@ -220,6 +221,13 @@ const MusicDetails = ({ route }) => {
|
||||
const handleSliderSeekStart = useCallback(async () => {
|
||||
if (!trackDescriptor) return;
|
||||
try {
|
||||
console.log("[MusicDetails.web] handleSliderSeekStart", {
|
||||
isCurrentTrack,
|
||||
isTrackPlaying,
|
||||
positionMs,
|
||||
durationMs,
|
||||
});
|
||||
lastSeekTargetMs.current = null;
|
||||
wasPlayingBeforeSeek.current = isTrackPlaying;
|
||||
if (!isCurrentTrack) {
|
||||
await ensureLoaded({
|
||||
@@ -240,6 +248,8 @@ const MusicDetails = ({ route }) => {
|
||||
ensureLoaded,
|
||||
positionMs,
|
||||
pauseTrack,
|
||||
lastSeekTargetMs,
|
||||
durationMs,
|
||||
]);
|
||||
|
||||
const handleSliderSeek = useCallback(
|
||||
@@ -247,6 +257,13 @@ const MusicDetails = ({ route }) => {
|
||||
const dur = durationMs || 0;
|
||||
if (!trackDescriptor || dur <= 0) return;
|
||||
const targetMs = Math.max(0, Math.floor(dur * ratio));
|
||||
lastSeekTargetMs.current = targetMs;
|
||||
console.log("[MusicDetails.web] handleSliderSeek", {
|
||||
ratio,
|
||||
durationMs: dur,
|
||||
targetMs,
|
||||
isCurrentTrack,
|
||||
});
|
||||
try {
|
||||
if (!isCurrentTrack) {
|
||||
await ensureLoaded({ startPositionMs: targetMs, autoPlay: false });
|
||||
@@ -261,14 +278,30 @@ const MusicDetails = ({ route }) => {
|
||||
);
|
||||
|
||||
const handleSliderSeekEnd = useCallback(async () => {
|
||||
const targetMs =
|
||||
typeof lastSeekTargetMs.current === "number"
|
||||
? Math.max(0, lastSeekTargetMs.current)
|
||||
: null;
|
||||
console.log("[MusicDetails.web] handleSliderSeekEnd", {
|
||||
targetMs,
|
||||
wasPlayingBeforeSeek: wasPlayingBeforeSeek.current,
|
||||
isCurrentTrack,
|
||||
positionMs,
|
||||
});
|
||||
try {
|
||||
if (wasPlayingBeforeSeek.current) {
|
||||
if (!isCurrentTrack) {
|
||||
await ensureLoaded({
|
||||
startPositionMs: positionMs,
|
||||
startPositionMs:
|
||||
targetMs !== null && Number.isFinite(targetMs)
|
||||
? targetMs
|
||||
: positionMs,
|
||||
autoPlay: true,
|
||||
});
|
||||
} else {
|
||||
if (targetMs !== null && Number.isFinite(targetMs)) {
|
||||
await seekTrackTo(targetMs);
|
||||
}
|
||||
await resumeTrack();
|
||||
}
|
||||
}
|
||||
@@ -276,8 +309,15 @@ const MusicDetails = ({ route }) => {
|
||||
console.log("MusicDetails seek end error", e?.message);
|
||||
} finally {
|
||||
wasPlayingBeforeSeek.current = false;
|
||||
lastSeekTargetMs.current = null;
|
||||
}
|
||||
}, [ensureLoaded, isCurrentTrack, positionMs, resumeTrack]);
|
||||
}, [
|
||||
ensureLoaded,
|
||||
isCurrentTrack,
|
||||
positionMs,
|
||||
resumeTrack,
|
||||
seekTrackTo,
|
||||
]);
|
||||
|
||||
const handleSeekBySeconds = useCallback(
|
||||
async (deltaSeconds) => {
|
||||
|
||||
Reference in New Issue
Block a user