Skip to content

Commit ba0309c

Browse files
update ee
1 parent 124dab9 commit ba0309c

File tree

1 file changed

+79
-57
lines changed

1 file changed

+79
-57
lines changed

docs/src/assets/music_player.js

Lines changed: 79 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,14 @@
693693
this.musicLibrary = musicLibrary;
694694
this.volume = state.volume || 0.15;
695695

696-
// Track popup opening (non-blocking)
697-
setTimeout(() => this.trackPopupEvent('opened'), 100);
696+
// Track popup opening (non-blocking, only if window is stable)
697+
setTimeout(() => {
698+
try {
699+
this.trackPopupEvent('opened');
700+
} catch (e) {
701+
// Silently handle tracking errors
702+
}
703+
}, 1000);
698704

699705
// Update volume UI
700706
document.getElementById('popup-volume').value = Math.round(this.volume * 100);
@@ -1135,73 +1141,89 @@
11351141

11361142
// Enhanced initialization with popup support
11371143
async function initialize() {
1138-
createTopBar();
1139-
1140-
// Try to restore previous audio state
1141-
const sys = window.meraEnhancedAudioSystem;
1142-
const savedState = localStorage.getItem('mera-was-playing');
1143-
const savedTrack = localStorage.getItem('mera-current-track');
1144-
const savedTime = parseFloat(localStorage.getItem('mera-audio-time') || '0');
1145-
1146-
if (savedState === 'true' && savedTrack) {
1147-
console.log(`🎵 Enhanced player - attempting to restore: ${savedTrack} at ${savedTime}s`);
1148-
const path = getMusicPath(savedTrack);
1149-
sys.audio.src = path;
1150-
sys.currentTrack = savedTrack;
1151-
sys.audio.currentTime = Math.max(0, savedTime - 1);
1144+
try {
1145+
console.log('🎵 Starting main music player initialization...');
1146+
createTopBar();
1147+
console.log('🎵 Top bar created successfully');
11521148

1153-
// Don't auto-play, just prepare for resume
1154-
sys.isPlaying = false;
1155-
}
1156-
1157-
updateUI();
1158-
1159-
// Monitor for navigation and recreate if needed
1160-
let currentUrl = window.location.href;
1161-
1162-
const checkForNavigation = async () => {
1163-
const newUrl = window.location.href;
1164-
if (newUrl !== currentUrl) {
1165-
currentUrl = newUrl;
1166-
console.log(`🎵 Enhanced player navigation: ${newUrl}`);
1149+
// Try to restore previous audio state
1150+
const sys = window.meraEnhancedAudioSystem;
1151+
const savedState = localStorage.getItem('mera-was-playing');
1152+
const savedTrack = localStorage.getItem('mera-current-track');
1153+
const savedTime = parseFloat(localStorage.getItem('mera-audio-time') || '0');
1154+
1155+
if (savedState === 'true' && savedTrack) {
1156+
console.log(`🎵 Enhanced player - attempting to restore: ${savedTrack} at ${savedTime}s`);
1157+
const path = getMusicPath(savedTrack);
1158+
sys.audio.src = path;
1159+
sys.currentTrack = savedTrack;
1160+
sys.audio.currentTime = Math.max(0, savedTime - 1);
11671161

1168-
setTimeout(() => {
1169-
if (!document.getElementById('mera-top-bar')) {
1170-
console.log('🎵 Recreating enhanced player UI...');
1171-
createTopBar();
1172-
}
1173-
updateUI();
1174-
}, 50);
1162+
// Don't auto-play, just prepare for resume
1163+
sys.isPlaying = false;
11751164
}
1176-
};
1177-
1178-
setInterval(checkForNavigation, 500);
1179-
window.addEventListener('popstate', checkForNavigation);
1180-
window.addEventListener('hashchange', checkForNavigation);
1181-
1182-
// DOM observer for recreation
1183-
if ('MutationObserver' in window) {
1184-
const observer = new MutationObserver(() => {
1185-
if (!document.getElementById('mera-top-bar')) {
1165+
1166+
updateUI();
1167+
1168+
// Monitor for navigation and recreate if needed
1169+
let currentUrl = window.location.href;
1170+
1171+
const checkForNavigation = async () => {
1172+
const newUrl = window.location.href;
1173+
if (newUrl !== currentUrl) {
1174+
currentUrl = newUrl;
1175+
console.log(`🎵 Enhanced player navigation: ${newUrl}`);
1176+
11861177
setTimeout(() => {
11871178
if (!document.getElementById('mera-top-bar')) {
1179+
console.log('🎵 Recreating enhanced player UI...');
11881180
createTopBar();
11891181
}
1182+
updateUI();
11901183
}, 50);
11911184
}
1192-
});
1185+
};
11931186

1194-
observer.observe(document.body, { childList: true, subtree: true });
1195-
}
1187+
setInterval(checkForNavigation, 500);
1188+
window.addEventListener('popstate', checkForNavigation);
1189+
window.addEventListener('hashchange', checkForNavigation);
1190+
1191+
// DOM observer for recreation
1192+
if ('MutationObserver' in window) {
1193+
const observer = new MutationObserver(() => {
1194+
if (!document.getElementById('mera-top-bar')) {
1195+
setTimeout(() => {
1196+
if (!document.getElementById('mera-top-bar')) {
1197+
createTopBar();
1198+
}
1199+
}, 50);
1200+
}
1201+
});
1202+
1203+
observer.observe(document.body, { childList: true, subtree: true });
1204+
}
1205+
1206+
// Periodic state saving
1207+
setInterval(() => {
1208+
if (sys.isPlaying && sys.activePlayer === 'topbar' && !sys.audio.paused) {
1209+
localStorage.setItem('mera-was-playing', 'true');
1210+
localStorage.setItem('mera-current-track', sys.currentTrack);
1211+
localStorage.setItem('mera-audio-time', sys.audio.currentTime.toString());
1212+
}
1213+
}, 2000);
11961214

1197-
// Periodic state saving
1198-
setInterval(() => {
1199-
if (sys.isPlaying && sys.activePlayer === 'topbar' && !sys.audio.paused) {
1200-
localStorage.setItem('mera-was-playing', 'true');
1201-
localStorage.setItem('mera-current-track', sys.currentTrack);
1202-
localStorage.setItem('mera-audio-time', sys.audio.currentTime.toString());
1215+
console.log('🎵 Main music player initialization completed successfully');
1216+
} catch (error) {
1217+
console.error('🎵 Music player initialization failed:', error);
1218+
// Try to create just the basic top bar without advanced features
1219+
try {
1220+
if (!document.getElementById('mera-top-bar')) {
1221+
createTopBar();
1222+
}
1223+
} catch (fallbackError) {
1224+
console.error('🎵 Even fallback music player creation failed:', fallbackError);
12031225
}
1204-
}, 2000);
1226+
}
12051227
}
12061228

12071229
// Make path calculation globally available

0 commit comments

Comments
 (0)