Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-21-2012, 02:04 AM   PM User | #1
rileyrelay
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rileyrelay is an unknown quantity at this point
Preload audio then start animation?

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?
Code:
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();
}
rileyrelay is offline   Reply With Quote
Old 11-21-2012, 06:57 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I assume your code is working, so it is calling the main() function that you didn't show here?

If yes, then
Code:
function main() {
   // whatever you want to do
   ...
   window.location.href = 'animation.html';
}
devnull69 is offline   Reply With Quote
Old 11-21-2012, 03:54 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Code:
<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?
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:44 PM.


Advertisement
Log in to turn off these ads.