Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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();
    }

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    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';
    }

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,399
    Thanks
    11
    Thanked 595 Times in 575 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •