fix: media explorer preview MIDI file từ Media Library (name/kind) không phát âm — resolve bytes /static/midi qua filePreviewUrl + guard playSelected/selectSynthInst/re-loop

This commit is contained in:
2026-08-11 08:39:48 +07:00
parent aa1cd8d5de
commit aae0b05473
2 changed files with 14 additions and 9 deletions
+7 -4
View File
@@ -14024,6 +14024,9 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
const filePreviewUrl = (f) => {
if (f && f.path && !(f.handle && f.handle.getFile)) return `${API_BASE_URL}/api/v1/media/file?path=${encodeURIComponent(f.path)}`;
// Media Library demo MIDI: ch có name/kind bytes /static/midi (bn
// resolveMediaExplorerDropFile cũng dùng cùng endpoint).
if (f && f.kind === 'midi' && f.name) return `${API_BASE_URL}/static/midi/${encodeURIComponent(f.name)}`;
const fid = f && (f.file_id || f.fileId);
return fid ? `${API_BASE_URL}/api/v1/audio/download/${fid}` : null;
};
@@ -14057,7 +14060,7 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
localStorage.setItem('studio_media_explorer_synth', JSON.stringify(inst));
// Realtime: re-schedule current MIDI preview with the newly selected instrument
const cur = selectedRef.current;
if (isPlayingRef.current && cur && isMidiFile(cur) && (cur.handle || cur.path || cur.file_id || cur.fileId)) {
if (isPlayingRef.current && cur && isMidiFile(cur) && (cur.handle || cur.path || cur.file_id || cur.fileId || (cur.kind === 'midi' && cur.name))) {
selectTokenRef.current++;
const token = selectTokenRef.current;
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}
@@ -14240,7 +14243,7 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
if (!f) return;
stopMediaPlayback();
if (isMidiFile(f)) {
if (f.handle || f.path || f.file_id || f.fileId) {
if (f.handle || f.path || f.file_id || f.fileId || (f.kind === 'midi' && f.name)) {
// Real MIDI file: play through selected synth instrument
await playMidiPreview(f, token);
return;
@@ -14533,7 +14536,7 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
try { localStorage.setItem('studio_media_explorer_tempo', String(clamped)); } catch (e) {}
// Re-schedule a currently playing MIDI preview at the new tempo.
const cur = selectedRef.current;
if (isPlayingRef.current && cur && isMidiFile(cur) && (cur.handle || cur.path || cur.file_id || cur.fileId)) {
if (isPlayingRef.current && cur && isMidiFile(cur) && (cur.handle || cur.path || cur.file_id || cur.fileId || (cur.kind === 'midi' && cur.name))) {
selectTokenRef.current++;
const token = selectTokenRef.current;
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}
@@ -14704,7 +14707,7 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
}
if (next && isMidiFile(cur)) {
// Re-schedule loop for the currently previewing MIDI file
if (cur && (cur.handle || cur.path || cur.file_id || cur.fileId)) {
if (cur && (cur.handle || cur.path || cur.file_id || cur.fileId || (cur.kind === 'midi' && cur.name))) {
selectTokenRef.current++;
const token = selectTokenRef.current;
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}