Fix APlayer instance scope in initialization

Refactored APlayer initialization to use a properly scoped variable for the instance, ensuring it is accessible outside the try block. This improves logging and debugging of the APlayer instance after creation.
This commit is contained in:
Sora 2026-01-20 10:02:50 +08:00
parent e251421fb8
commit 08b5e3bc85

View File

@ -76,9 +76,10 @@
console.log('Container styles:', window.getComputedStyle(container)); console.log('Container styles:', window.getComputedStyle(container));
console.log('Creating APlayer with playlist:', playlist); console.log('Creating APlayer with playlist:', playlist);
let ap;
try { try {
const ap = new APlayer({ ap = new APlayer({
container: container, container: container,
lrcType: 0, lrcType: 0,
audio: playlist, audio: playlist,
@ -98,19 +99,19 @@
// Log initialization // Log initialization
console.log('APlayer initialized with', playlist.length, 'tracks'); console.log('APlayer initialized with', playlist.length, 'tracks');
console.log('APlayer instance:', ap); console.log('APlayer instance:', ap);
// Check if APlayer created DOM elements // Check if APlayer created DOM elements
setTimeout(() => { setTimeout(() => {
const aplayerElements = container.querySelectorAll('*'); const aplayerElements = container.querySelectorAll('*');
console.log('APlayer created', aplayerElements.length, 'child elements'); console.log('APlayer created', aplayerElements.length, 'child elements');
if (aplayerElements.length === 0) { if (aplayerElements.length === 0) {
console.error('APlayer did not create any child elements - initialization failed'); console.error('APlayer did not create any child elements - initialization failed');
} else { } else {
console.log('APlayer child elements:', aplayerElements); console.log('APlayer child elements:', aplayerElements);
} }
}, 100); }, 100);
} catch (error) { } catch (error) {
console.error('APlayer initialization failed:', error); console.error('APlayer initialization failed:', error);
return; return;