I can get audio.currentTime but not set it (in Google Chrome)

It drives me crazy. Here is the code that I use to set the current time:

$("#audio").click(function(e) { e.preventDefault(); mr_waveform_skip(e) }); function mr_waveform_skip(event) { clientX = event.clientX; left = event.currentTarget.offsetLeft; clickoffset = clientX - left; percent = clickoffset/event.currentTarget.offsetWidth audio_duration = audio_element.duration; duration_seek = percent*audio_duration; audio_element.currentTime = duration_seek; // audio_element.currentTime = 10; console.log('CLICK: ' + duration_seek + ' Element: ' + audio_element + ' CurrentTime: ' + audio_element.currentTime); } 

I can't seem to set audio_element.currentTime just to get it!

And even worse, it works in fireFox! Chrome reloads to 0, no matter what.

This is what the above code is generated in the Firefox console:

 CLICK: 63.82905432385121 Element: [object HTMLAudioElement] CurrentTime: 3.849546 

And in Chrome:

 CLICK: 63.82905432385121 Element: [object HTMLAudioElement] CurrentTime: 3.849546 

Cm? The one! We see that Chromes sees the HTML audio element (since it can get the value). If I do audio_element.currentTime = 10; , it still doesn't work ( in Chrome , Firefox loyally restarts at 10).

+6
source share
2 answers

Your code works fine when I tested it using the Ogg file from Wikipedia. If this is really your code, then this problem occurs due to any distortion or unexpected format in your media file.

You cannot fix this problem with code; You will need to create a new media file that your browser can process correctly. Perhaps try using another part of the audio programs (or different settings) to create or reprogram the media file.

+2
source

If the format is not a problem:

I ran into this issue in Chrome a couple of times today. So much time was spent trying to solve it. (Version 55.x)

The solution is to restart Chrome. After countless page updates, the value is suddenly not set. This is probably a cache error. I would like to emphasize that using a development server that supports range queries is also a good idea.

If I do not start Node or Django, I use: https://github.com/danvk/RangeHTTPServer

+1
source

Source: https://habr.com/ru/post/987576/


All Articles