-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
453 lines (401 loc) · 21.5 KB
/
Copy pathindex.html
File metadata and controls
453 lines (401 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<!DOCTYPE html>
<!--------------------------------------*
* - iTunes api - searching
* - lyrics.ovh - lyrics
* - youtube data v3 - player
* - RapidAPI (rapidapi.com/ytdlfree/api/youtube-v3-alternative) - cycling player
*--------------------------------------->
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Music Player</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.4.0/color-thief.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsmediatags/3.9.5/jsmediatags.min.js"></script>
<link rel="stylesheet" href="css/all.css" />
<link rel="icon" href="img/favicon.png" type="image/x-icon">
<meta name="description" content="A simple and elegant static music player. Listen to your favourite songs for free with no ads directly in your browser." />
<meta name="keywords" content="music player, static music player, web music player, HTML music player, JavaScript music player" />
<meta name="author" content="Hydrovolter" />
<meta property="og:title" content="Hydro's Music Player" />
<meta name="og:description" content="A simple and elegant static music player. Listen to your favourite songs for free with no ads directly in your browser." />
<meta property="og:image" content="img/favicon.png" />
<meta property="og:site_name" content="Hydro's Music Player" />
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PWJ73HJC1X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-PWJ73HJC1X');
</script>
</head>
<body>
<div class="app-container">
<div class="main-content">
<div class="search-container">
<input
type="text"
class="search-input"
placeholder="Search for any song..."
id="searchInput"
autocomplete="off"
/>
<div class="search-results" id="searchResults">
</div>
</div>
<div class="player-area">
<div class="player">
<div class="album-art">
<img
src="img/empty_art.png"
alt="Album"
id="albumCover"
crossorigin="anonymous"
/>
</div>
<div class="info" id="playerInfo">
<div class="track-title" id="trackTitle">Not Playing</div>
<div class="artist" id="artistName">Not Playing</div>
<div class="controls">
<i id="prevBtn" class="icon icon-prev"></i>
<i id="playPause" class="icon icon-play"></i>
<i id="nextBtn" class="icon icon-next"></i>
<i id="volumeBtn" class="icon icon-volume"></i>
<i id="loopBtn" class="icon icon-loop"></i>
<i id="shuffleBtn" class="icon icon-shuffle"></i>
<i id="likeBtn" class="icon icon-heart-empty"></i>
<i id="addToPlaylistBtn" class="icon icon-plus-circle"></i>
</div>
<div id="seekbar" class="seekbar"><div id="progress"></div></div>
<div class="timecodes">
<span id="currentTime">0:00</span>
<span id="remainingTime">-0:00</span>
</div>
</div>
<div class="lyrics-info" id="lyricsInfo">
<div class="lyrics-header">
<div>
<div class="lyrics-title" id="lyricsSongTitle">Not Playing</div>
<div class="lyrics-artist" id="lyricsArtistName">Not Playing</div>
</div>
</div>
<div class="lyrics-content" id="lyricsContent">
No lyrics available.
</div>
</div>
</div>
</div>
</div>
<div class="playlist-sidebar" id="playlistSidebar">
<div class="playlist-sidebar-header">
<button id="backToPlaylistsBtn" class="sidebar-back-button icon-button" title="Back to playlists" style="display: none;">
<i class="icon icon-arrow-left"></i>
</button>
<h3 id="sidebarTitle">Your Playlists</h3>
<button id="createNewPlaylistBtn" class="create-playlist-btn">+</button>
</div>
<div class="playlist-content" id="playlistDisplayArea">
</div>
</div>
</div>
<!-- Bottom Controls Bar -->
<div class="bottom-controls-bar">
<div class="lyrics-toggle" id="lyricsToggle">
<i class="icon icon-lyrics"></i>
</div>
<div class="settings-toggle" id="settingsToggle" title="Settings">
<i class="icon icon-settings"></i>
</div>
</div>
<div id="player-container">
<div id="ytPlayer"></div>
</div>
<audio id="html5AudioPlayer" style="display: none;"></audio>
<div id="addToPlaylistModal" class="modal" style="display:none;">
<div class="modal-content">
<span class="close-modal-btn" id="closeAddToPlaylistModal">×</span>
<h4>Add to Playlist</h4>
<div id="modalPlaylistList">
<!-- Playlists will be dynamically inserted here -->
</div>
</div>
</div>
<div id="generalModal" class="modal" style="display:none;">
<div class="modal-content">
<span class="close-modal-btn" id="closeGeneralModal">×</span>
<h4 id="generalModalTitle">Notification</h4>
<p id="generalModalMessage" style="text-align: center; margin-bottom: 20px;"></p>
<div id="generalModalActions" style="text-align: center;">
<!-- Buttons will be dynamically inserted here -->
</div>
</div>
</div>
<!-- Create Playlist Modal -->
<div id="createPlaylistModal" class="modal" style="display:none;">
<div class="modal-content">
<span class="close-modal-btn" id="closeCreatePlaylistModal">×</span>
<h4 id="createPlaylistModalTitle">Create New Playlist</h4>
<div class="modal-artwork-section">
<div class="playlist-artwork-editor" id="createPlaylistArtworkEditor">
<img src="img/empty_art.png" alt="Playlist Artwork" id="createPlaylistArtworkPreview" class="modal-artwork-preview">
<div class="edit-overlay">
<i class="icon icon-edit"></i>
<span>Click or drag image</span>
</div>
</div>
<button id="clearCreatePlaylistArtworkBtn" class="modal-button tertiary clear-artwork-btn" style="display:none;">Clear Artwork</button>
</div>
<input type="file" id="createPlaylistArtworkInput" accept="image/*" style="display:none;">
<div class="form-group" style="margin-bottom: 20px;">
<label for="newPlaylistNameInput" style="display: block; margin-bottom: 8px; font-weight: 500;">Playlist Name:</label>
<input type="text" id="newPlaylistNameInput" class="modal-input" placeholder="My Awesome Playlist">
</div>
<div id="createPlaylistModalActions" style="text-align: right;">
<button id="cancelCreatePlaylistBtn" class="modal-button secondary" style="margin-right: 10px;">Cancel</button>
<button id="confirmCreatePlaylistBtn" class="modal-button success">Create</button>
</div>
</div>
</div>
<!-- Edit Playlist Modal (formerly Rename Playlist Modal) -->
<div id="editPlaylistModal" class="modal" style="display:none;">
<div class="modal-content">
<span class="close-modal-btn" id="closeEditPlaylistModal">×</span>
<h4 id="editPlaylistModalTitle">Edit Playlist</h4>
<div class="modal-artwork-section">
<div class="playlist-artwork-editor" id="editPlaylistArtworkEditor">
<img src="img/empty_art.png" alt="Playlist Artwork" id="editPlaylistArtworkPreview" class="modal-artwork-preview">
<div class="edit-overlay">
<i class="icon icon-edit"></i>
<span>Click or drag image</span>
</div>
</div>
<button id="clearEditPlaylistArtworkBtn" class="modal-button tertiary clear-artwork-btn" style="display:none;">Clear Artwork</button>
</div>
<input type="file" id="editPlaylistArtworkInput" accept="image/*" style="display:none;">
<div class="form-group" style="margin-bottom: 20px;">
<label for="editPlaylistNameInput" style="display: block; margin-bottom: 8px; font-weight: 500;">Playlist Name:</label>
<input type="text" id="editPlaylistNameInput" class="modal-input" placeholder="Enter new name">
</div>
<div id="editPlaylistModalActions" style="text-align: right;">
<button id="cancelEditPlaylistBtn" class="modal-button secondary" style="margin-right: 10px;">Cancel</button>
<button id="confirmEditPlaylistBtn" class="modal-button success">Save Changes</button>
</div>
</div>
</div>
<!-- Settings Modal -->
<div id="settingsModal" class="modal" style="display:none;">
<div class="modal-content">
<span class="close-modal-btn" id="closeSettingsModal">×</span>
<h4 id="settingsModalTitle">Settings</h4>
<div class="settings-section">
<h5>Import Spotify Playlist</h5>
<p class="settings-description">
Enter the public Spotify playlist URL to import it.
<br>This will create a new playlist in your app.
</p>
<div class="form-group" style="margin-bottom: 10px;">
<input type="text" id="spotifyPlaylistUrlInput" class="modal-input" placeholder="https://open.spotify.com/playlist/...">
</div>
<button id="importSpotifyPlaylistBtn" class="modal-button success">Import Playlist</button>
<p id="spotifyImportStatus" class="selected-file-name-display" style="margin-top: 8px;"></p>
</div>
<div class="settings-section">
<h5>Export Data</h5>
<p class="settings-description">Download your playlists and app data as a JSON file.</p>
<button id="exportDataBtn" class="modal-button secondary">Export My Data</button>
</div>
<!-- <hr class="settings-divider"> -->
<div class="settings-section last-content-section">
<h5>Import Data</h5>
<p class="settings-description">Import data from a previously exported file.
<br><strong>Warning:</strong> This will overwrite your current playlists and data. This action cannot be undone.
</p>
<div id="importFileDropZone" class="file-drop-zone">
<input type="file" id="importDataInput" accept=".json,application/json" style="display: none;">
<span class="drop-zone-prompt">Drag & drop your .json file here, or click to select</span>
</div>
<button id="importDataBtn" class="modal-button primary" style="margin-top: 10px;" disabled>Import Selected File</button>
<p id="selectedFileName" class="selected-file-name-display"></p>
</div>
<!-- GitHub Commit Info Footer -->
<div class="settings-modal-footer">
<i class="icon icon-github"></i>
<a href="https://github.com/Hydrovolter/Music" target="_blank" rel="noopener noreferrer" class="commit-link" id="githubCommitLink">
<span id="latestCommitSha" title="View commit on GitHub"></span>
</a>
<span class="commit-separator">·</span>
<span id="latestCommitTimeAgo" title=""></span>
</div>
</div>
</div>
<input type="file" id="localFilesInput" multiple accept="audio/*,.mp3,.m4a,.ogg,.wav,.flac" style="display: none;">
<div id="toastContainer" class="toast-container">
<!-- Toasts will be dynamically added here -->
</div>
<!-- Credits Footer -->
<div class="credits-footer">
<span>Made with </span>
<span class="credit-heart">❤️</span>
<span> by </span>
<a href="https://hydrovolter.com" target="_blank" rel="noopener noreferrer" class="credit-link">Hydrovolter</a>
</div>
<script src="js/endpoints.js"></script>
<script src="js/init.js"></script>
<script src="js/modals.js"></script>
<script src="js/toast.js"></script>
<script src="js/bg.js"></script>
<script src="js/playlist.js"></script>
<script src="js/player.js"></script>
<script src="js/history.js"></script>
<script src="js/search.js"></script>
<script src="js/play.js"></script>
<script src="js/getYT.js"></script>
<script src="js/lyrics.js"></script>
<script src="js/playback.js"></script>
<script>
document.addEventListener("click", function (e) {
// Ensure searchInput and searchResults are defined before accessing contains
if (typeof searchInput !== 'undefined' && typeof searchResults !== 'undefined' &&
!searchResults.contains(e.target) && e.target !== searchInput) {
if (typeof hideSearchResults === 'function') hideSearchResults();
}
});
document.addEventListener('DOMContentLoaded', () => {
if (typeof initializeModals === 'function') { // Initialize the new modal system
initializeModals();
} else {
console.error("initializeModals function not found.");
}
if (typeof initializePlaylistSystem === 'function') { // Initialize the playlist system
initializePlaylistSystem();
} else {
console.error("initializePlaylistSystem function not found.");
}
// +++ START: ADD HTML5 AUDIO PLAYER AND YOUTUBE PLAYER INITIALIZATION +++
// Get reference to the HTML5 audio player (declared in init.js)
html5AudioPlayer = document.getElementById('html5AudioPlayer');
if (html5AudioPlayer) {
console.log("HTML5 Audio Player element found. Attaching listeners.");
html5AudioPlayer.addEventListener('play', () => {
// This event fires when playback begins or resumes.
if (currentPlayingWith === 'html5') {
isPlaying = true;
if (playPauseBtn) {
playPauseBtn.classList.remove("icon-play");
playPauseBtn.classList.add("icon-pause");
}
console.log("HTML5 Audio: Play event");
}
});
html5AudioPlayer.addEventListener('pause', () => {
// This event fires when playback is paused.
if (currentPlayingWith === 'html5') {
isPlaying = false;
if (playPauseBtn) {
playPauseBtn.classList.remove("icon-pause");
playPauseBtn.classList.add("icon-play");
}
console.log("HTML5 Audio: Pause event");
}
});
html5AudioPlayer.addEventListener('ended', () => {
console.log("HTML5 Audio: Ended event. Loop:", loopState, "PlaylistID:", currentPlayingPlaylistId);
if (currentPlayingWith === 'html5') {
isPlaying = false;
if (playPauseBtn) {
playPauseBtn.classList.remove("icon-pause");
playPauseBtn.classList.add("icon-play");
}
if (loopState === 'song' && currentTrack && currentTrack.isLocalFile) {
console.log("HTML5 Audio: Looping current song.");
html5AudioPlayer.currentTime = 0;
html5AudioPlayer.play().catch(e => {
console.error("Error re-playing local file on loop:", e);
showToast("Error looping track.", 3000);
});
} else if (currentPlayingPlaylistId && typeof playNextTrackInCurrentPlaylist === 'function') {
const playlist = getPlaylistById(currentPlayingPlaylistId); // from playlist.js
if (playlist && playlist.songs && playlist.songs.length > 0) {
const isLastTrack = currentPlaylistTrackIndex >= playlist.songs.length - 1;
if (isShuffleActive || loopState === 'playlist' || (loopState === 'none' && !isLastTrack)) {
console.log("HTML5 Audio: Playing next track from playlist.");
playNextTrackInCurrentPlaylist(); // This will call playSong()
} else {
console.log("HTML5 Audio: End of playlist, no loop/shuffle to continue.");
if(typeof clearPlayerStateOnEnd === 'function') clearPlayerStateOnEnd();
}
} else {
console.log("HTML5 Audio: Playlist context invalid or empty for 'ended' event.");
if(typeof clearPlayerStateOnEnd === 'function') clearPlayerStateOnEnd();
}
} else {
console.log("HTML5 Audio: No loop and no playlist context to continue.");
if(typeof clearPlayerStateOnEnd === 'function') clearPlayerStateOnEnd();
}
}
});
html5AudioPlayer.addEventListener('loadedmetadata', () => {
// This fires when metadata (including duration) is loaded.
if (currentPlayingWith === 'html5' && currentTrack && currentTrack.isLocalFile) {
const newDuration = Math.round(html5AudioPlayer.duration);
if (currentTrack.durationSeconds !== newDuration) {
currentTrack.durationSeconds = newDuration;
console.log(`HTML5 Audio: Metadata loaded, duration updated to ${newDuration}s for ${currentTrack.title}`);
}
// updateProgress() is called by a setInterval, so it will pick up the new duration.
// Or you can call it here for immediate update:
if(typeof updateProgress === 'function') updateProgress();
}
});
html5AudioPlayer.addEventListener('error', (e) => {
console.error("HTML5 Audio Player Error Event:", html5AudioPlayer.error, e);
if (currentPlayingWith === 'html5') {
showToast("Error playing local audio file.", 3000);
isPlaying = false;
if (playPauseBtn) {
playPauseBtn.classList.remove("icon-pause");
playPauseBtn.classList.add("icon-play");
}
// Consider trying next song or clearing player state
if(typeof clearPlayerStateOnEnd === 'function') clearPlayerStateOnEnd();
}
});
// `timeupdate` is frequent; `updateProgress` is handled by setInterval,
// which is generally fine for UI updates. If you need more precise sync,
// you could listen to `timeupdate` on `html5AudioPlayer` and call `updateProgress`.
// html5AudioPlayer.addEventListener('timeupdate', updateProgress); // Optional
} else {
console.error("HTML5 Audio Player element (#html5AudioPlayer) not found in the DOM!");
}
// YouTube Player Initialization
// The global onYouTubeIframeAPIReady function is defined in player.js
// The YouTube Iframe API script will call it automatically when it's ready.
// We just need to ensure player.js is loaded before this script block if onYouTubeIframeAPIReady is there.
// (Your script order seems correct for this)
// If you needed to manually trigger it (e.g., if player.js wasn't defining the global function directly):
/*
if (typeof YT === 'undefined' || typeof YT.Player === 'undefined') {
console.log("YouTube API not ready yet, window.onYouTubeIframeAPIReady will handle it.");
// No explicit action here, player.js's global onYouTubeIframeAPIReady will be called
} else {
// API is already available (e.g., script re-run or very fast load)
console.log("YouTube API already ready, calling onPlayerReady setup manually (if needed).");
if (typeof onYouTubeIframeAPIReady === 'function' && !player) { // Ensure player isn't already init
// onYouTubeIframeAPIReady(); // This would create the YT.Player
}
}
*/
// For your current setup, where player.js defines `onYouTubeIframeAPIReady` globally,
// you don't need the manual check/call here. The YouTube API script handles it.
console.log("Base initializations complete (modals, playlist, audio players setup).");
});
</script>
</body>
</html>