Selaa lähdekoodia

fix(EditSong): song duration would sometimes be reset when the video changed state

Kristian Vos 2 vuotta sitten
vanhempi
commit
9aab322024
1 muutettua tiedostoa jossa 58 lisäystä ja 30 poistoa
  1. 58 30
      frontend/src/components/modals/EditSong/index.vue

+ 58 - 30
frontend/src/components/modals/EditSong/index.vue

@@ -1104,12 +1104,22 @@ export default {
 					if (currentTime !== undefined)
 						this.youtubeVideoCurrentTime = currentTime.toFixed(3);
 
-					if (this.youtubeVideoDuration === "0.000") {
+					if (this.youtubeVideoDuration.indexOf(".000") !== -1) {
 						const duration = this.video.player.getDuration();
 
 						if (duration !== undefined) {
+							if (
+								`${this.youtubeVideoDuration}` ===
+								`${Number(this.song.duration).toFixed(3)}`
+							)
+								this.song.duration = duration.toFixed(3);
+
 							this.youtubeVideoDuration = duration.toFixed(3);
-							this.youtubeVideoNote = "(~)";
+							if (
+								this.youtubeVideoDuration.indexOf(".000") !== -1
+							)
+								this.youtubeVideoNote = "(~)";
+							else this.youtubeVideoNote = "";
 
 							this.drawCanvas();
 						}
@@ -1164,39 +1174,56 @@ export default {
 								const newYoutubeVideoDuration =
 									youtubeDuration.toFixed(3);
 
-								const songDurationNumber = Number(
-									this.song.duration
-								);
-								const songDurationNumber2 =
-									Number(this.song.duration) + 1;
-								const songDurationNumber3 =
-									Number(this.song.duration) - 1;
-								const fixedSongDuration =
-									songDurationNumber.toFixed(3);
-								const fixedSongDuration2 =
-									songDurationNumber2.toFixed(3);
-								const fixedSongDuration3 =
-									songDurationNumber3.toFixed(3);
-
 								if (
-									this.youtubeVideoDuration !==
-										newYoutubeVideoDuration &&
-									(fixedSongDuration ===
-										this.youtubeVideoDuration ||
-										fixedSongDuration2 ===
+									this.youtubeVideoDuration.indexOf(
+										".000"
+									) !== -1 &&
+									`${this.youtubeVideoDuration}` !==
+										`${newYoutubeVideoDuration}`
+								) {
+									const songDurationNumber = Number(
+										this.song.duration
+									);
+									const songDurationNumber2 =
+										Number(this.song.duration) + 1;
+									const songDurationNumber3 =
+										Number(this.song.duration) - 1;
+									const fixedSongDuration =
+										songDurationNumber.toFixed(3);
+									const fixedSongDuration2 =
+										songDurationNumber2.toFixed(3);
+									const fixedSongDuration3 =
+										songDurationNumber3.toFixed(3);
+
+									if (
+										`${this.youtubeVideoDuration}` ===
+											`${Number(
+												this.song.duration
+											).toFixed(3)}` &&
+										(fixedSongDuration ===
 											this.youtubeVideoDuration ||
-										fixedSongDuration3 ===
-											this.youtubeVideoDuration)
-								)
-									this.song.duration =
+											fixedSongDuration2 ===
+												this.youtubeVideoDuration ||
+											fixedSongDuration3 ===
+												this.youtubeVideoDuration)
+									)
+										this.song.duration =
+											newYoutubeVideoDuration;
+
+									this.youtubeVideoDuration =
 										newYoutubeVideoDuration;
-
-								this.youtubeVideoDuration =
-									newYoutubeVideoDuration;
-								this.youtubeVideoNote = "";
+									if (
+										this.youtubeVideoDuration.indexOf(
+											".000"
+										) !== -1
+									)
+										this.youtubeVideoNote = "(~)";
+									else this.youtubeVideoNote = "";
+								}
 
 								if (this.song.duration === -1)
-									this.song.duration = youtubeDuration;
+									this.song.duration =
+										this.youtubeVideoDuration;
 
 								youtubeDuration -= this.song.skipDuration;
 								if (this.song.duration > youtubeDuration + 1) {
@@ -1269,6 +1296,7 @@ export default {
 			this.thumbnailHeight = null;
 			this.youtubeVideoCurrentTime = "0.000";
 			this.youtubeVideoDuration = "0.000";
+			this.youtubeVideoNote = "";
 			this.socket.dispatch("apis.leaveRoom", `edit-song.${songId}`);
 			if (this.$refs.saveButton) this.$refs.saveButton.status = "default";
 		},