Monday 15 April 2013

google chrome - Html5 audio "preload="none" messes up pause() and currentTime() -


I have a very awkward problem in preventing and resetting the progression of html5 audio.

If I set Preload = "none", then "Pause"; And "current time = 0;" I will not execute at the moment I have already removed = "none", everything works.

This is my code. I fade in / out some pages, each page has an html5 audio element in the same location (intent), so when the user visits that page, Can run.

  $ ('.link'). ('Click', function (e) {$ ('.jpg container & gt; div'). Feodaut (); $ (this.getAttribute ("href"). Fadein (); stop audio);}); Stop the function stop audio () {// fade out and any current audio $ ('audio'). Anamat ({volume: 0}, 1000); SetTimeout (function () {$ .each ($ ('audio'), function () {this.currentTime = 0; this.pause (); Alert ('Audio is turned off and reset');}}} }, 1000 ()) $$ ('Play', function () {// when the volume was faded, then reset the amount when click on Play button $ ('Audio') . ({Volume: 1} 100);}); .... .... & lt; A href = "# page1" class = "link" & gt; Audio 1 & lt; / A & gt; & Lt; A href = "# page2" class = "link" & gt; Audio 2 & lt; / A & gt; & Lt; A href = "# page3" class = "link" & gt; Audio 3 & lt; / A & gt; & Lt; Div class = "page container" & gt; & Lt; Div id = "page1" & gt; // All three audio elements are exact same place. Click on the current audio and click on the link, and enter a new & lt; Audio control loop class = "sound" preload = "none" & gt; & Lt; Source src = "../../ site / music / music 1.mp3" /> & Lt; Source src = "../../ site / music / music 1. og" /> & Lt; / Audio & gt; & Lt; / Div & gt; & Lt; Div id = "page2" & gt; & Lt; Audio control loop class = "sound" preload = "none" & gt; & Lt; Source src = "../../ site / music / music 2.mp3" /> & Lt; Source src = "../../ site / music / music 2. og" /> & Lt; / Audio & gt; & Lt; / Div & gt; & Lt; Div id = "page3" & gt; & Lt; Audio control loop class = "sound" preload = "none" & gt; & Lt; Source src = "../../ site / music / music 3. mp3" /> & Lt; Source src = "../../ site / music / music 3.ogg" /> & Lt; / Audio & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

When I click on a link on any other page, I need to pause and reset all three audio elements. I am currently not shutting down, at the moment I I click the play button in the audio element, which contains a fade fade, I play two audiences at the same time. However the interesting thing is that the audio gets spoiled.

As I have already removed, if no "none" is removed, then the warning ('Audio has been shut down and reset'), and everything will work fine .

Do anyone know that I can load audio when needed (if I take preload = "none") then my website will not work in Chrome, almost 20 music files to all Will try to load on it hang Chrome for a while), but do my script work?

Thanks!

Setting the current time on an audio tag that triggers a DOM exception that has not been loaded yet So make sure the audio is loaded. Just try to set its current time.

  $ ("audio"). A ("load data", function ($ {$ (this). Data ("dataloaded", true);}); $ .each ($ ('audio'), function () {if ($ (this) .data ("Dataloaded")) {this.currentTime = 0; this.pause ();} Alerts ('Audio is turned off and reset');});    < / Html>

No comments:

Post a Comment