I'm attempting to update the currentTime
of an html audio element, however, it keeps resetting to 0
no matter what value I give it.
I've confirmed that the values I'm passing are less than the audio file's duration, and greater that 0
. The following code works as-intended locally in an html file, but exhibits this strange behavior in my Django app.
HTML:
<audio id="my-audio" preload="true" src="path/to/file.mp3" type="audio/mp3"></audio>
JavaScript:
var audio = document.getElementById('my-audio')
audio.play()
console.log(audio.currentTime) // result: 0.997171 or similar
console.log(audio.duration) // result 3596.06855
audio.currentTime = 500
console.log(audio.currentTime) // result: 0
All my other audio-related functions are working. This strange behavior occurs with multiple different audio files. I've searched SO for a solution, but nothing seems relevant to my particular case. I'm thinking that is has something to do with Django's server per the following comment from another thread. But I can't find any more information about this.
I am facing the same issue. It's working on a piece of code, but when i integrate it in a Django application, it fails. It works on Firefox but not on Google Chrome. Video / Audio file doesn't matter, it happens with any file i try on the code. The time i am trying to seek to is less than the duration of the video.
Any help/ tips are greatly appreciated. Thanks for reading.
* Edit: I can confirm that this is not an issue in Firefox, and this works as intended. I suppose this is an issue specifically with Chrome.
For anyone struggling with the same issue. I was uploading media assets to my static directory through django-admin. For some reason (only in chrome) my assets were missing necessary headers: Accept-Ranges: bytes
and Content-Range: bytes <some bytes>/<total bytes>
. I could not find a simpler solution, so I routed my file uploads to post to an AWS S3 bucket where I could easily manage permissions/ headers, etc. I followed this tutorial and implementation was really easy. To my understanding, this (dedicated hosting of non-static files) is typically what is supposed to happen anyway. I hope no one struggles with this ever again.