fix(music): audio element yüklenme düzelt

This commit is contained in:
2026-01-02 00:32:12 +03:00
parent e49c2ac75d
commit 17faec5874

View File

@@ -1,5 +1,5 @@
<script> <script>
import { onMount } from "svelte"; import { onMount, tick } from "svelte";
import { API, apiFetch, withToken } from "../utils/api.js"; import { API, apiFetch, withToken } from "../utils/api.js";
import { musicCount } from "../stores/musicStore.js"; import { musicCount } from "../stores/musicStore.js";
import { cleanFileName } from "../utils/filename.js"; import { cleanFileName } from "../utils/filename.js";
@@ -76,7 +76,7 @@
} }
// Player functions // Player functions
function playTrack(item, index) { async function playTrack(item, index) {
if (currentTrack?.id === item.id) { if (currentTrack?.id === item.id) {
togglePlay(); togglePlay();
return; return;
@@ -87,13 +87,13 @@
duration = item.mediaInfo?.format?.duration || 0; duration = item.mediaInfo?.format?.duration || 0;
isPlaying = true; isPlaying = true;
if (audioEl) { await tick();
audioEl.src = streamURL(item); if (!audioEl) return;
audioEl.play().catch((err) => { audioEl.src = streamURL(item);
console.error("Play error:", err); audioEl.play().catch((err) => {
isPlaying = false; console.error("Play error:", err);
}); isPlaying = false;
} });
} }
function togglePlay() { function togglePlay() {