...

View Full Version : Preload audio then start animation?



rileyrelay
11-21-2012, 02:04 AM
Hi.. I'm using CSS3/HTML5 to replace Flash. My animation needs an MP3/OGG to start at the same time it does, and apparently I can only use JavaScript to pre-load it but I know NOTHING about JS.

Is there a way I can get this code to redirect from my welcome.html to animation.html when the files are finished?


mySound = loadAudio('/audio/valmp3.ogg');
mySound2 = loadAudio2('/audio/valmp3.mp3');

filesToLoad = 2;
filesLoaded = 0;


function loadAudio(uri)
{
var audio = new Audio();
//audio.onload = isAppLoaded;
audio.addEventListener('canplaythrough', isAppLoaded, false);
audio.src = uri;
return audio;
}

function loadAudio2(uri)
{
var audio = new Audio();
//audio.onload = isAppLoaded;
audio.addEventListener('canplaythrough', isAppLoaded, false);
audio.src = uri;
return audio;
}

function isAppLoaded()
{
filesLoaded++;
if (filesLoaded >= filesToLoad) main();
}

devnull69
11-21-2012, 06:57 AM
I assume your code is working, so it is calling the main() function that you didn't show here?

If yes, then


function main() {
// whatever you want to do
...
window.location.href = 'animation.html';
}

rnd me
11-21-2012, 03:54 PM
<audio preload="auto" controls src='...'>

if you re-direct, what's the point of loading the audio only to throw it away as soon as it's loaded?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum