Skip to content

Commit

Permalink
[#N/A] Made the JS update the audio file when next or previous button…
Browse files Browse the repository at this point in the history
…s are pressed.
  • Loading branch information
paulmckissock committed Jul 29, 2024
1 parent 1269850 commit 8170c44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion audioapp/management/commands/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions audioapp/templates/audioapp/for_you.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ <h2 class="text-xl font-bold">Comments</h2>
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';
Expand Down
1 change: 1 addition & 0 deletions audioapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8170c44

Please sign in to comment.