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:
@@ -14024,6 +14024,9 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
|
|||||||
|
|
||||||
const filePreviewUrl = (f) => {
|
const filePreviewUrl = (f) => {
|
||||||
if (f && f.path && !(f.handle && f.handle.getFile)) return `${API_BASE_URL}/api/v1/media/file?path=${encodeURIComponent(f.path)}`;
|
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 (bản
|
||||||
|
// 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);
|
const fid = f && (f.file_id || f.fileId);
|
||||||
return fid ? `${API_BASE_URL}/api/v1/audio/download/${fid}` : null;
|
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));
|
localStorage.setItem('studio_media_explorer_synth', JSON.stringify(inst));
|
||||||
// Realtime: re-schedule current MIDI preview with the newly selected instrument
|
// Realtime: re-schedule current MIDI preview with the newly selected instrument
|
||||||
const cur = selectedRef.current;
|
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++;
|
selectTokenRef.current++;
|
||||||
const token = selectTokenRef.current;
|
const token = selectTokenRef.current;
|
||||||
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}
|
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;
|
if (!f) return;
|
||||||
stopMediaPlayback();
|
stopMediaPlayback();
|
||||||
if (isMidiFile(f)) {
|
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
|
// Real MIDI file: play through selected synth instrument
|
||||||
await playMidiPreview(f, token);
|
await playMidiPreview(f, token);
|
||||||
return;
|
return;
|
||||||
@@ -14533,7 +14536,7 @@ const MediaExplorerPanel = ({ height, clipboardRef, active }) => {
|
|||||||
try { localStorage.setItem('studio_media_explorer_tempo', String(clamped)); } catch (e) {}
|
try { localStorage.setItem('studio_media_explorer_tempo', String(clamped)); } catch (e) {}
|
||||||
// Re-schedule a currently playing MIDI preview at the new tempo.
|
// Re-schedule a currently playing MIDI preview at the new tempo.
|
||||||
const cur = selectedRef.current;
|
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++;
|
selectTokenRef.current++;
|
||||||
const token = selectTokenRef.current;
|
const token = selectTokenRef.current;
|
||||||
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}
|
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)) {
|
if (next && isMidiFile(cur)) {
|
||||||
// Re-schedule loop for the currently previewing MIDI file
|
// 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++;
|
selectTokenRef.current++;
|
||||||
const token = selectTokenRef.current;
|
const token = selectTokenRef.current;
|
||||||
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}
|
try { if (window.SonicSF && typeof window.SonicSF.stopAll === 'function') window.SonicSF.stopAll(); } catch (e) {}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user