javascript - Audio Player in HTML 5 not working properly in chrome.(Forward & Rewind play) -
i having problem in running html5 audio player in chrome.it working fine in ie 9+ , firefox. have written javascript functions forwarding , rewinding audio player on f7 & f8 key press,its woring fine in ie , ff reasons not working in chrome.following code.
$(document).keydown(function (e) { if (e.keycode == 118) { rewindaudio(); return false; } else if (e.keycode == 119) { forwardaudio(); return false; } } // rewinds audio file 30 seconds. function rewindaudio() { // check audio element support. if (window.htmlaudioelement) { try { var oaudio = audioplayerinfocus[0]; oaudio.currenttime -= 1.0; } catch (e) { // fail silently show in f12 developer tools console if (window.console && console.error("error:" + e)); } } } // fast forwards audio file 1 seconds. function forwardaudio() { // check audio element support. if (window.htmlaudioelement) { try { var oaudio = audioplayerinfocus[0 oaudio.currenttime += 1.0; } catch (e) { // fail silently show in f12 developer tools console if (window.console && console.error("error:" + e)); } } }
i suspect currenttime not changing in chrome.is there syntax mistake or browser related issue?please me.thank you.
the following code works in browser have tested me - fiddle:
<audio controls> <source src="sample/one.mp3" type="audio/mpeg"> </audio> <script type="text/javascript"> $(document).on('keydown',function(e) { if (e.keycode == 82) { console.log('r key = rewind'); rewindaudio(); } else if(e.keycode == 70){ console.log('f key = forward'); forwardaudio(); } }); function rewindaudio() { console.log('rewindaudio'); oaudio = $('audio')[0]; oaudio.currenttime -= 1.0; } function forwardaudio() { console.log('forwardaudio'); oaudio = $('audio')[0]; oaudio.currenttime += 1.0; } </script>
i have read people having specific design f7 key.
on side note detect html5 audio support use functions described in here.
Comments
Post a Comment