how to get audio.duration value by a function

because you’re relying on an event to fire, you can’t return a value in getDuration or getVal instead, you want to use a callback function, like this (callbacks) The example assume you want to put the duration into a span written like this <span id=”duration”></span> function getDuration(src, cb) { var audio = new Audio(); $(audio).on(“loadedmetadata”, … Read more

How do I make an file play continuously on all pages?

Yes, it is possible. try this: <audio preload=”auto” src=”https://stackoverflow.com/questions/15612120/a.mp3″ loop=”true” autobuffer> Unsupported in Firefox </audio> <script> function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? “” : “; expires=”+exdate.toUTCString()); document.cookie=c_name + “=” + c_value; } function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(“;”); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf(“=”)); y=ARRcookies[i].substr(ARRcookies[i].indexOf(“=”)+1); x=x.replace(/^\s+|\s+$/g,””); if (x==c_name) { return … Read more

“Autoplay” HTML5 audio player on mobile browsers

This question has been answered in other places before. Regarding Apple devices specifically: Can you autoplay HTML5 videos on the iPad? “Apple has made the decision to disable the automatic playing of video on iOS devices, through both script and attribute implementations. In Safari, on iOS (for all devices, including iPad), where the user may … Read more

HTML5 audio playlist – how to play a second audio file after the first has ended?

Here’s a JSLinted, unobtrusive Javascript example demonstrating how to handle and use the ended mediaevent. In your particular situation, you would trigger playback of the second audio file in your ended event handler. You can use the code below or run the test fiddle. Click an item in the playlist to begin playback. After one … Read more

Using local file as src

I can think of two ways. Within your audio tag: src=”https://stackoverflow.com/questions/21737224/file:///C:/.file.mp3″ or you could use a Blob using the file API. HTML: <input type=”file”></input> JS: audio.src = URL.createObjectURL(document.getElementsByTagName(‘input’)[0].files[0]);

HTML 5 Audio Tag Multiple Files

In javascript you can do it like this (this is just to get you started): audio = new Audio(“start url”); audio.addEventListener(‘ended’,function(){ audio.src = “https://stackoverflow.com/questions/18274061/new url”; audio.pause(); audio.load(); audio.play(); }); if you want you can also use the same player(jquery): var audio = $(“#player”);