enter image description here I connected a plugin for styling an audio player, everything works, but it gives errors, sometimes there can be more and sometimes less, how to fix them?

<div class="audio"> <audio preload="auto" controls><source src="audio/audio.mp3"></audio> <script src="js/audioplayer.js"></script> <script>$( function() { $( 'audio' ).audioPlayer(); } );</script> </div> </div> <script> (function(doc){var addEvent='addEventListener',type='gesturestart',qsa='querySelectorAll',scales=[1,1],meta=qsa in doc?doc[qsa]('meta[name=viewport]'):[];function fix(){meta.content='width=device-width,minimum-scale='+scales[0]+',maximum-scale='+scales[1];doc.removeEventListener(type,fix,true);}if((meta=meta[meta.length-1])&&addEvent in doc){fix();scales=[.25,1.6];doc[addEvent](type,fix,true);}}(document)); $( function() { $( 'audio' ).audioPlayer(); } ); </script> 

enter image description here

Plugin code: https://jsfiddle.net/ucrutva5/

  • If this is not a self-written plugin , add a link to the source code . - Kosta B.
  • I hope I understood you correctly and added what was needed to the question) - aquido
  • Well, from the error message, you can see that the bug is in the plugin (going beyond the array when calling TimeRanges.end) - MSDN.WhiteKnight
  • And is it possible to fix this somehow? - aquido

2 answers 2

Edit the updateLoadBar method (line 101) so

 updateLoadBar = setInterval( function() { if (theAudio.onprogress) { barLoaded.width( ( theAudio.buffered.end( 0 ) / theAudio.duration ) * 100 + '%' ); if( theAudio.buffered.end( 0 ) >= theAudio.duration ) clearInterval( updateLoadBar ); } }, 100 ); 

Source: https://stackoverflow.com/questions/25651719/why-does-audio-buffered-end0-get-an-error-message-when-i-try-to-get-buffered-t

  • Thank you very much, after a lot of torment they helped me - aquido
  1. Строка 106 в jsfiddle -

    barLoaded.width ((theAudio.buffered.end (0) / theAudio.duration) * 100 + '%');

The fact is that, you call the end method (as I understand the jQuery library method), on an element in which it is empty, you must handle the error through if or something else. For theAudio object, the duration property is set to NaN, which means that when you exit this expression, you get NaN. 2. You are not given normal debugging by setInterval which executes this code every millisecond (100) - which is very fast, and the console is clogged with constant calls with the same error, preferably at least to be removed for debugging. 3. I want to say that the duration property will generate an error in the code and further as it has the value NaN - any arithmetic operation with NaN gives NaN.

This error was avoided here is the link jsfiddle

  • The beginning of the code with 101 lines, and increased setInterval, you can return to its original state, no error will occur. - Ilya Rogatkin