this not work me! having same issue? code seems straightforward plays once need able play on , over. see follows:
my html:
<audio id="siren" src="sounds/400.ogg" preload="auto">
and js:
function play_siren() { log("play sound"); if(document.getelementbyid('siren').paused == true){ document.getelementbyid('siren').play(); } } function pause_siren() { try{ if(document.getelementbyid('siren').paused == false){ document.getelementbyid('siren').pause(); } log("paused siren"); }catch(err){ log(err.message); } try{ if(document.getelementbyid('siren').currenttime > 0.0){ document.getelementbyid('siren').currenttime = 0.0; } log("reset siren"); }catch(err){ log(err.message); } }
it started programmatically in js code follows:
if(obj[3].siren == true && isplayingsiren == false){ play_siren(); isplayingsiren = true; }else if(obj[3].siren == false && isplayingsiren == true){ pause_siren(); isplayingsiren = false; }
i found gentleman's code , seem work: http://html5.komplett.cc/code/chap_video/js_audioplayer_en.html
but setting "currenttime = 0" not doing me.
i can't figure out. tested chrome, firefox , safari. firefox not work @ far chrome seems best html5 still can play once.
i tried mp3 , ogg same behavior.
please shed light. thank you!
here full html:
<html> <head> <meta charset="utf-8"> <link rel="stylesheet" media="all" href="js_audioplayer.css"> <title>htmlmediaelement example - audio player</title> <script src="../js/audioplayer.js"></script> </head> <body> <fieldset> <audio src="sounds/400.ogg" preload="auto"></audio> <legend>audio player (400)</legend> </fieldset> <script> function loadxmldoc(){ _pause(); updateprogress(0); playpause(); } var loadxmltimer = setinterval(loadxmldoc, 2000); </script> </body> </html>
and here full javascript:
// global callback functions var playpause, updateprogress, _play, _pause; /* initialize audio player */ window.onload = function() { // keep track of playback status var audiostatus = { isplaying : false }; // define references audio, pulldown menu, play-button, slider , time display var audio = document.queryselector("audio"); /* load track menu-index */ var loadtrack = function(idx) { audio.src = '../sounds/400.ogg'; audio.load(); }; /* callback play or pause */ _play = function() { audio.play(); log("play"); audiostatus.isplaying = true; }; _pause = function() { audio.pause(); log("pause"); audiostatus.isplaying = false; }; playpause = function() { if (audio.paused) { _play(); } else { _pause(); } }; /* callback set or update playback position */ updateprogress = function(value) { audio.currenttime = value; log("updateprogress"); }; };
the timer plays sounds programmatically on expiration. works long private. did not understand why has private.
does pass thru if statement?
you use ontimeupdate placing value of document.getelementbyid('siren').currenttime in variable. if set more 0, update in if conditionnal.
Comments
Post a Comment