SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Play sounds sequentially?

    Is there any way to play more than one song in the BG, but one at a time?

    Say I have two files, intro.mp3 and loop.mp3.

    What I want is to play intro.mp3, and when its done playing, to play loop.mp3 and loop it 3 times.

    Is there any way to preload the songs before they play so that there isn't a gap between when intro ends and loop begins?

    I also made copies of the files with whitespace inserted so that if I had to have them both play at the same time, loop wouldn't have any music until its supposed to, but again, I need to preload the songs before playing them.

    I have no problem having the music not play by itself, but rather have the user click a button first after the songs have been loaded, but I don't know how to do this at all. I've tried several things but ntohing seems to work.

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    I use .base

    Hi takerfan,

    bss=new Array("images/lb.wav","images/mb.wav","images/hb.wav")
    tbl=new Array("images/lt.wav","images/mt.wav","images/ht.wav")

    drum=new Array(bss,tbl)


    if (lhgt == 0) {
    document.all.base.src=(drum[l][2])
    }
    if (rhgt == 0) {
    document.all.base.src=(drum[2][1])
    }

    and in the BODY
    <bgsound id="base">

    I use a loop to play a series of drumsounds depending on an Array

    I dont know if this method is cross-browser friendly as it only works with .wav and .wma files so far.(no affect with .mp3)
    If you take a look at....
    www.unitingrhythms.com/drums/drumrhythms/drum1.html
    This is my script at work(offline through website).
    at the moment it doesn't work that well, maybe because I want the sounds try to play to quickly, and as they are .wav they are 22k each for a half second sound!!
    If you are only doing a couple of things and the time lengths are long then it should be ok.
    I use the same method to put sounds with rollovers.
    If there is a fault, can anyone let me know
    Also, does anyone know if two sounds can be controlled by rollovers, the first not being stopped by the rollover of the second. my balaphon at www.unitingrhythms.com/arts uses the .base well, but one sound gets stopped by the next.(a thought to try...wonder if .base0 or .base1 works...)

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    sorry, your working with mp3!!

    I dont think this method works with .mp3.
    Unless I made a mistake in my programming(which I do often and it usually take ages to find), .base wont change an mp3 file. It works with .wma and I can get them to almost the same size, but does .wma work cross browser?

    I had a script before, but it was longer.
    I transformed a sound-rollover script found from the web.
    I think this works cross browser
    <head>
    <script language="javascript" type="text/javascript">
    if (top.location.href.indexOf("buddy.html") == -1)
    top.location.href = "index.html";
    </script>

    <script language="javascript" type="text/javascript">
    function change1()
    {parent.drum.location="plrhythm1.html";}
    function change2()
    {parent.drum.location="plrhythm2.html";}
    </script>
    <script language="javascript" type="text/javascript">
    img1=new Image()
    img1.src="images/rhythm1out.gif"
    img2=new Image()
    img2.src="images/rhythm2out.gif"
    img3=new Image()
    img3.src="images/rhythm1over.gif"
    img4=new Image()
    img4.src="images/rhythm2over.gif"
    </script>
    <script language="javascript" type="text/javascript">
    var aySound = new Array();
    aySound[0] = "images/rhythm1sound.wav";
    aySound[1] = "images/rhythm2sound.wav";

    document.write('<BGSOUND ID="auIEContainer">')
    IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
    NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
    ver4 = IE||NS? 1:0;
    onload=auPreload;

    function auPreload() {
    if (!ver4) return;
    if (NS) auEmb = new Layer(0,window);
    else {
    Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
    document.body.insertAdjacentHTML("BeforeEnd",Str);
    }
    var Str = '';
    for (i=0;i<aySound.length;i++)
    Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
    if (IE) auEmb.innerHTML = Str;
    else {
    auEmb.document.open();
    auEmb.document.write(Str);
    auEmb.document.close();
    }
    auCon = IE? document.all.auIEContainer:auEmb;
    auCon.control = auCtrl;
    }
    function auCtrl(whSound,play) {
    if (IE) this.src = play? aySound[whSound]:'';
    else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
    }
    function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
    function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }

    </script>
    </head>

    <body bgcolor="E8D6AE">

    <A HREF="javascript:change1()"
    onMouseover="document.images['one'].src=img3.src, playSound(0)"
    onMouseout="document.images['one'].src=img1.src, stopSound(0)">
    <IMG SRC="images/rhythm1out.gif" NAME="one" BORDER="0"></A>
    <A HREF="javascript:change2()"
    onMouseover="document.images['two'].src=img4.src, playSound(1)"
    onMouseout="document.images['two'].src=img2.src, stopSound(1)">
    <IMG SRC="images/rhythm2out.gif" NAME="two" BORDER=0></A>
    </body>

    I hope this helps

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Talking .base works for mp3's

    Tried to play an mp3 in my (now working!!!) website and it works, so try the first idea. I'm still having problems preloading and naming sound files, so every time it tries to play it has to contact the site. This can be overcome by making the page available offline, so if you have a lot of sound files to play I would put a suggestion on the site for the viewers! Have Fun!!!
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

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