|
693 | 693 | this.musicLibrary = musicLibrary; |
694 | 694 | this.volume = state.volume || 0.15; |
695 | 695 |
|
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); |
698 | 704 |
|
699 | 705 | // Update volume UI |
700 | 706 | document.getElementById('popup-volume').value = Math.round(this.volume * 100); |
|
1135 | 1141 |
|
1136 | 1142 | // Enhanced initialization with popup support |
1137 | 1143 | 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'); |
1152 | 1148 |
|
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); |
1167 | 1161 |
|
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; |
1175 | 1164 | } |
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 | + |
1186 | 1177 | setTimeout(() => { |
1187 | 1178 | if (!document.getElementById('mera-top-bar')) { |
| 1179 | + console.log('🎵 Recreating enhanced player UI...'); |
1188 | 1180 | createTopBar(); |
1189 | 1181 | } |
| 1182 | + updateUI(); |
1190 | 1183 | }, 50); |
1191 | 1184 | } |
1192 | | - }); |
| 1185 | + }; |
1193 | 1186 |
|
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); |
1196 | 1214 |
|
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); |
1203 | 1225 | } |
1204 | | - }, 2000); |
| 1226 | + } |
1205 | 1227 | } |
1206 | 1228 |
|
1207 | 1229 | // Make path calculation globally available |
|
0 commit comments