Add ability to play music

This commit is contained in:
2024-11-18 13:09:09 +11:00
parent 5cfa2f40f7
commit b92cb4408a
5 changed files with 303 additions and 139 deletions
+212 -7
View File
@@ -46,34 +46,40 @@
background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
display: flex;
justify-content: center;
gap: 1rem;
flex-wrap: wrap;
gap: 0.5rem;
opacity: 0;
transition: opacity 0.3s;
}
.slideshow-container:hover .controls {
.slideshow-container:hover .controls,
.controls:focus-within {
opacity: 1;
}
.control-button {
background: rgba(255,255,255,0.1);
border: none;
color: white;
padding: 0.5rem 1rem;
padding: 0.5rem;
border-radius: 0.375rem;
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
transition: background-color 0.2s;
font-size: 0.9rem;
min-width: 44px;
min-height: 44px;
justify-content: center;
}
.control-button:hover {
background: rgba(255,255,255,0.2);
}
.progress-circle {
position: fixed;
bottom: 2rem;
right: 2rem;
width: 32px;
height: 32px;
bottom: 1rem;
right: 1rem;
width: 24px;
height: 24px;
z-index: 50;
opacity: 0.8;
}
@@ -90,6 +96,92 @@
transform: rotate(-90deg);
transform-origin: center;
}
.music-playlist {
position: fixed;
bottom: 5rem;
left: 50%;
transform: translateX(-50%);
background-color: rgba(0, 0, 0, 0.9);
padding: 1rem;
border-radius: 0.5rem;
display: none;
width: 90%;
max-width: 400px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
.playlist-content {
max-height: 60vh;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.playlist-items {
margin-top: 1rem;
}
.playlist-item {
padding: 0.75rem;
cursor: pointer;
color: #fff;
border-radius: 0.375rem;
transition: background-color 0.2s;
font-size: 1rem;
min-height: 44px;
display: flex;
align-items: center;
}
.playlist-item:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.playlist-item.active {
background-color: rgba(59, 130, 246, 0.5);
font-weight: 500;
}
.playlist-content h3 {
color: #fff;
margin: 0;
font-size: 1.1rem;
font-weight: 500;
text-align: center;
}
@media (max-width: 768px) {
.controls {
padding: 0.75rem;
gap: 0.25rem;
}
.control-button {
padding: 0.5rem;
font-size: 0.8rem;
}
.control-button span {
display: none;
}
.control-button svg {
width: 20px;
height: 20px;
}
.music-playlist {
bottom: 4rem;
}
#musicText {
display: inline !important;
font-size: 0.8rem;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
@media (max-width: 480px) {
.music-playlist {
width: 95%;
max-height: 50vh;
}
.playlist-item {
padding: 0.5rem;
font-size: 0.9rem;
}
}
</style>
{% endblock %}
@@ -131,6 +223,18 @@
</svg>
<span>{% trans "Next" %}</span>
</button>
<button class="control-button" onclick="toggleMusic()" id="musicBtn">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" id="musicIcon">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.536 8.464a5 5 0 010 7.072m2.828-9.9a9 9 0 010 12.728M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"/>
</svg>
<span id="musicText">{% trans "Mute" %}</span>
</button>
<button class="control-button" onclick="togglePlaylist()">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
</svg>
<span>{% trans "Playlist" %}</span>
</button>
<button class="control-button" onclick="exitSlideshow()">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
@@ -139,11 +243,30 @@
</button>
</div>
</div>
<audio id="backgroundMusic" loop>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="music-playlist">
<div class="playlist-content">
<h3>{% trans "Music Playlist" %}</h3>
<div class="playlist-items" id="playlistItems">
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
const playlist = [
{ title: 'Purple Planet', src: '{% static "music/Purple-Planet.mp3" %}' },
{ title: 'Gentle Rain', src: '{% static "music/mixkit-just-kidding.mp3" %}' },
{ title: 'Ocean Waves', src: '{% static "music/Thomas-the-Tank-Engine.mp3" %}' }
];
let currentSlide = 0;
let currentSongIndex = 0;
const slides = document.querySelectorAll('.slide');
const totalSlides = slides.length;
let slideInterval = null;
@@ -152,6 +275,61 @@ let isPlaying = true;
const INTERVAL_TIME = 5000; // 5 seconds
let startTime = null;
let animationFrame = null;
const backgroundMusic = document.getElementById('backgroundMusic');
let isMusicPlaying = true;
function loadSong(index) {
currentSongIndex = (index + playlist.length) % playlist.length;
const song = playlist[currentSongIndex];
backgroundMusic.src = song.src;
if (isMusicPlaying && isPlaying) {
backgroundMusic.play();
}
updateMusicDisplay();
populatePlaylist();
}
function nextSong() {
loadSong(currentSongIndex + 1);
}
function previousSong() {
loadSong(currentSongIndex - 1);
}
function updateMusicDisplay() {
const musicText = document.getElementById('musicText');
const currentSong = playlist[currentSongIndex];
musicText.textContent = isMusicPlaying ? `${currentSong.title} (Playing)` : `${currentSong.title} (Muted)`;
}
function toggleMusic() {
isMusicPlaying = !isMusicPlaying;
const icon = document.getElementById('musicIcon');
if (isMusicPlaying) {
backgroundMusic.play();
icon.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.536 8.464a5 5 0 010 7.072m2.828-9.9a9 9 0 010 12.728M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"/>';
} else {
backgroundMusic.pause();
icon.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1.586l4.707-4.707C10.923 3.663 12 4.109 12 5v14c0 .891-1.077 1.337-1.707.707L5.586 15z"/>';
}
updateMusicDisplay();
}
function togglePlaylist() {
const playlistPanel = document.querySelector('.music-playlist');
if (playlistPanel.style.display === 'none' || playlistPanel.style.display === '') {
playlistPanel.style.display = 'block';
} else {
playlistPanel.style.display = 'none';
}
}
function selectSong(index) {
loadSong(index);
togglePlaylist();
}
function showSlide(index) {
slides.forEach(slide => slide.classList.remove('active'));
@@ -177,10 +355,12 @@ function togglePlayPause() {
startSlideshow();
icon.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 9v6m4-6v6"/>';
text.textContent = '{% trans "Pause" %}';
if (isMusicPlaying) backgroundMusic.play();
} else {
stopSlideshow();
icon.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/>';
text.textContent = '{% trans "Play" %}';
backgroundMusic.pause();
}
}
@@ -189,6 +369,7 @@ function startSlideshow() {
startTime = Date.now();
slideInterval = setInterval(nextSlide, INTERVAL_TIME);
updateProgress();
if (isMusicPlaying) backgroundMusic.play();
}
function stopSlideshow() {
@@ -198,6 +379,7 @@ function stopSlideshow() {
animationFrame = null;
}
startTime = null;
backgroundMusic.pause();
}
function exitSlideshow() {
@@ -237,6 +419,15 @@ function resetProgress() {
}
}
function populatePlaylist() {
const playlistItems = document.getElementById('playlistItems');
playlistItems.innerHTML = playlist.map((song, index) => `
<div class="playlist-item ${index === currentSongIndex ? 'active' : ''}" onclick="selectSong(${index})">
${song.title} ${index === currentSongIndex ? '(Current)' : ''}
</div>
`).join('');
}
// Keyboard controls
document.addEventListener('keydown', (e) => {
switch(e.key) {
@@ -249,14 +440,28 @@ document.addEventListener('keydown', (e) => {
case ' ':
togglePlayPause();
break;
case 'm':
toggleMusic();
break;
case 'Escape':
exitSlideshow();
break;
case '[':
previousSong();
break;
case ']':
nextSong();
break;
case 'p':
togglePlaylist();
break;
}
});
// Start slideshow when page loads
document.addEventListener('DOMContentLoaded', () => {
populatePlaylist();
loadSong(0);
startSlideshow();
});
</script>
+91 -132
View File
@@ -629,30 +629,22 @@ video {
right: 0px;
}
.right-2 {
right: 0.5rem;
.right-1\.5 {
right: 0.375rem;
}
.top-0 {
top: 0px;
}
.top-2 {
top: 0.5rem;
.top-1\.5 {
top: 0.375rem;
}
.top-full {
top: 100%;
}
.right-1\.5 {
right: 0.375rem;
}
.top-1\.5 {
top: 0.375rem;
}
.z-0 {
z-index: 0;
}
@@ -739,6 +731,10 @@ video {
margin-right: 0.5rem;
}
.mt-0\.5 {
margin-top: 0.125rem;
}
.mt-1 {
margin-top: 0.25rem;
}
@@ -775,8 +771,11 @@ video {
margin-top: 2rem;
}
.mt-0\.5 {
margin-top: 0.125rem;
.line-clamp-1 {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
}
.line-clamp-2 {
@@ -793,13 +792,6 @@ video {
-webkit-line-clamp: 3;
}
.line-clamp-1 {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
}
.block {
display: block;
}
@@ -808,6 +800,10 @@ video {
display: inline-block;
}
.inline {
display: inline;
}
.flex {
display: flex;
}
@@ -860,18 +856,6 @@ video {
height: 1.5rem;
}
.h-auto {
height: auto;
}
.h-full {
height: 100%;
}
.h-screen {
height: 100vh;
}
.h-8 {
height: 2rem;
}
@@ -884,6 +868,18 @@ video {
height: 280px;
}
.h-auto {
height: auto;
}
.h-full {
height: 100%;
}
.h-screen {
height: 100vh;
}
.w-12 {
width: 3rem;
}
@@ -916,14 +912,14 @@ video {
width: 1.5rem;
}
.w-full {
width: 100%;
}
.w-8 {
width: 2rem;
}
.w-full {
width: 100%;
}
.min-w-0 {
min-width: 0px;
}
@@ -1052,6 +1048,10 @@ video {
justify-content: space-between;
}
.gap-1\.5 {
gap: 0.375rem;
}
.gap-2 {
gap: 0.5rem;
}
@@ -1060,24 +1060,11 @@ video {
gap: 1rem;
}
.gap-1\.5 {
gap: 0.375rem;
}
.gap-x-4 {
-moz-column-gap: 1rem;
column-gap: 1rem;
}
.gap-x-8 {
-moz-column-gap: 2rem;
column-gap: 2rem;
}
.gap-y-10 {
row-gap: 2.5rem;
}
.gap-y-8 {
row-gap: 2rem;
}
@@ -1388,11 +1375,6 @@ video {
background-color: rgb(254 249 195 / var(--tw-bg-opacity));
}
.bg-gray-900 {
--tw-bg-opacity: 1;
background-color: rgb(17 24 39 / var(--tw-bg-opacity));
}
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
@@ -1512,6 +1494,11 @@ video {
padding-bottom: 0.25rem;
}
.py-1\.5 {
padding-top: 0.375rem;
padding-bottom: 0.375rem;
}
.py-12 {
padding-top: 3rem;
padding-bottom: 3rem;
@@ -1542,11 +1529,6 @@ video {
padding-bottom: 2rem;
}
.py-1\.5 {
padding-top: 0.375rem;
padding-bottom: 0.375rem;
}
.pl-3 {
padding-left: 0.75rem;
}
@@ -1789,11 +1771,6 @@ video {
color: rgb(133 77 14 / var(--tw-text-opacity));
}
.text-gray-300 {
--tw-text-opacity: 1;
color: rgb(209 213 219 / var(--tw-text-opacity));
}
.underline {
text-decoration-line: underline;
}
@@ -2008,11 +1985,6 @@ video {
background-color: rgb(185 28 28 / var(--tw-bg-opacity));
}
.hover\:bg-gray-700:hover {
--tw-bg-opacity: 1;
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
}
.hover\:text-blue-200:hover {
--tw-text-opacity: 1;
color: rgb(191 219 254 / var(--tw-text-opacity));
@@ -2083,11 +2055,6 @@ video {
color: rgb(153 27 27 / var(--tw-text-opacity));
}
.hover\:text-white:hover {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.hover\:underline:hover {
text-decoration-line: underline;
}
@@ -2210,6 +2177,10 @@ video {
margin-right: 0px;
}
.sm\:mb-6 {
margin-bottom: 1.5rem;
}
.sm\:ml-3 {
margin-left: 0.75rem;
}
@@ -2218,30 +2189,22 @@ video {
margin-left: 1rem;
}
.sm\:mt-0 {
margin-top: 0px;
}
.sm\:mt-4 {
margin-top: 1rem;
}
.sm\:mb-6 {
margin-bottom: 1.5rem;
}
.sm\:mr-2 {
margin-right: 0.5rem;
}
.sm\:mt-1 {
margin-top: 0.25rem;
.sm\:mt-0 {
margin-top: 0px;
}
.sm\:mt-2 {
margin-top: 0.5rem;
}
.sm\:mt-4 {
margin-top: 1rem;
}
.sm\:block {
display: block;
}
@@ -2282,14 +2245,6 @@ video {
width: 2.5rem;
}
.sm\:w-64 {
width: 16rem;
}
.sm\:w-auto {
width: auto;
}
.sm\:w-12 {
width: 3rem;
}
@@ -2298,6 +2253,14 @@ video {
width: 1.25rem;
}
.sm\:w-64 {
width: 16rem;
}
.sm\:w-auto {
width: auto;
}
.sm\:grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@@ -2360,18 +2323,14 @@ video {
border-radius: 0.375rem;
}
.sm\:p-12 {
padding: 3rem;
}
.sm\:p-6 {
padding: 1.5rem;
}
.sm\:p-1\.5 {
padding: 0.375rem;
}
.sm\:p-12 {
padding: 3rem;
}
.sm\:p-3 {
padding: 0.75rem;
}
@@ -2380,11 +2339,25 @@ video {
padding: 1rem;
}
.sm\:p-6 {
padding: 1.5rem;
}
.sm\:px-4 {
padding-left: 1rem;
padding-right: 1rem;
}
.sm\:px-6 {
padding-left: 1.5rem;
padding-right: 1.5rem;
}
.sm\:py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.sm\:py-3 {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
@@ -2395,16 +2368,6 @@ video {
padding-bottom: 1rem;
}
.sm\:px-4 {
padding-left: 1rem;
padding-right: 1rem;
}
.sm\:py-2 {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.sm\:py-8 {
padding-top: 2rem;
padding-bottom: 2rem;
@@ -2414,29 +2377,29 @@ video {
text-align: left;
}
.sm\:text-base {
font-size: 1rem;
line-height: 1.5rem;
}
.sm\:text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}
.sm\:text-2xl {
font-size: 1.5rem;
line-height: 2rem;
}
.sm\:text-3xl {
font-size: 1.875rem;
line-height: 2.25rem;
}
.sm\:text-base {
font-size: 1rem;
line-height: 1.5rem;
}
.sm\:text-lg {
font-size: 1.125rem;
line-height: 1.75rem;
}
.sm\:text-3xl {
font-size: 1.875rem;
line-height: 2.25rem;
.sm\:text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}
}
@@ -2445,10 +2408,6 @@ video {
display: table-cell;
}
.md\:grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.md\:grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
Binary file not shown.
Binary file not shown.
Binary file not shown.