Parcourir la source

fix: SoundCloud player would sometimes send a pause event a few miliseconds before a finished event, added debounce/timeout to account for this

Kristian Vos il y a 1 an
Parent
commit
5c613a1591
1 fichiers modifiés avec 9 ajouts et 6 suppressions
  1. 9 6
      frontend/src/composables/useSoundcloudPlayer.ts

+ 9 - 6
frontend/src/composables/useSoundcloudPlayer.ts

@@ -12,6 +12,7 @@ export const useSoundcloudPlayer = () => {
 	const volume = ref();
 	const readyCallback = ref();
 	const attemptsToPlay = ref(0);
+	const debouncePause = ref(null);
 
 	const playAttemptTimeout = ref();
 
@@ -121,6 +122,8 @@ export const useSoundcloudPlayer = () => {
 	};
 
 	const changeTrackState = newTrackState => {
+		clearTimeout(debouncePause.value);
+
 		const oldTrackState = trackState.value;
 
 		trackState.value = newTrackState;
@@ -347,13 +350,13 @@ export const useSoundcloudPlayer = () => {
 		console.debug(TAG, "On pause", eventValue);
 
 		const finishedPlaying = eventValue.relativePosition === 1;
-		if (finishedPlaying) {
-			changeTrackState("finished");
-			return;
-		}
+		if (finishedPlaying) return;
 
-		if (trackState.value !== "attempting_to_play")
-			changeTrackState("paused");
+		clearTimeout(debouncePause.value);
+		debouncePause.value = setTimeout(() => {
+			if (trackState.value !== "attempting_to_play")
+				changeTrackState("paused");
+		}, 500);
 	});
 
 	soundcloudBindListener("finish", () => {