From 8170c445dfde9deb93198ab21f9862692d2eed76 Mon Sep 17 00:00:00 2001 From: Paul McKissock Date: Mon, 29 Jul 2024 18:18:29 -0400 Subject: [PATCH] [#N/A] Made the JS update the audio file when next or previous buttons are pressed. --- audioapp/management/commands/seed.py | 2 +- audioapp/templates/audioapp/for_you.html | 7 +++++-- audioapp/views.py | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/audioapp/management/commands/seed.py b/audioapp/management/commands/seed.py index 325155c2..551967f4 100644 --- a/audioapp/management/commands/seed.py +++ b/audioapp/management/commands/seed.py @@ -27,7 +27,7 @@ def handle(self, *args, **options): users.append(user) # Get the sample .mp3 file - sample_audio_path = os.path.join("audioapp", "sample_audio", "baby_shark.mp3") + sample_audio_path = os.path.join("audioapp", "sample_audio", "test.mp3") if not os.path.exists(sample_audio_path): self.stdout.write(self.style.ERROR("Sample audio file not found.")) return diff --git a/audioapp/templates/audioapp/for_you.html b/audioapp/templates/audioapp/for_you.html index 9e08cb6c..bee07bdb 100644 --- a/audioapp/templates/audioapp/for_you.html +++ b/audioapp/templates/audioapp/for_you.html @@ -79,15 +79,18 @@

Comments

xhr.onload = function () { if (xhr.status === 200) { // so the the player doesn't reload everytime an action is performed + var data = JSON.parse(xhr.responseText); if (action == "next" || action == "previous") { var audioPlayer = document.getElementById('audio-player'); + var audioSource = document.getElementById('audio-source'); + audioSource.src = data.audio_source; audioPlayer.load(); if (document.getElementById('autoplay-checkbox').checked) { audioPlayer.play(); } - document.getElementById('comment-form').reset(); + document.getElementById('comment-form').reset(); } - var data = JSON.parse(xhr.responseText); + document.getElementById('audio-title').textContent = data.title; document.getElementById('audio-description').textContent = data.description; document.getElementById('audio-like-count').textContent = data.like_count + ' Likes'; diff --git a/audioapp/views.py b/audioapp/views.py index bed7cd09..06a66dbb 100644 --- a/audioapp/views.py +++ b/audioapp/views.py @@ -150,6 +150,7 @@ def fyp_xml_http_request(audio_file, reached_end, fyp_index, request): "username": audio_file.user.username, "like_count": audio_file.like_set.count(), "profile_url": reverse("user_detail", args=[audio_file.user.username]), + "audio_source": audio_file.file.url, "comments": [ { "user": comment.user.username,