Page 1 of 1

Detect finish of embedded audio [RESOLVED]

Posted: Sun Oct 09, 2011 6:32 pm
by califdon
I'm still playing with an interactive JS page that plays several .mp3 files when certain conditions occur. Most are musical pieces, from 1 to 3 minutes in duration. I would really like to trigger some other actions when the .mp3 file completes playing, since the lengths are different. I am using the function DHTMLSound(), about which I can find very little useful information (but it is working). Does anyone know if there's any kind of event triggered at the conclusion of playing an .mp3 file, that could be captured?

[Edit: I've gotten around the issue by storing the actual playing duration of each file, in an array with the filenames, so now I just pull both the filename AND the duration (and a description, as a matter of fact) and use the duration to setTimeout() whatever I want to happen when it is finished. That works just fine, although I'm still curious whether there's an "audio complete" event or something like that.]

Re: Detect finish of embedded audio

Posted: Mon Oct 10, 2011 4:46 am
by Weirdan
Can you post the source code of that DHTMLSound() function? I'm pretty sure it's not one of browser-provided functions.

Re: Detect finish of embedded audio

Posted: Mon Oct 10, 2011 6:44 pm
by califdon

Code: Select all

function DHTMLSound(surl) {
         document.getElementById("dummyspan").innerHTML=
         "<embed src='"+surl+"' hidden=true autostart=true loop=false>";      
}
then you simply have a dummy span with display:none somewhere in your HTML:

Code: Select all

<span id='dummyspan'></span>
That was working in all current browsers, but you know the story: I made some changes and introduced errors, so now it works properly only in FF.

Anyway, I have gotten around my original problem by storing the filenames and playing durations in an array, for loading, then customizing the setTimeout call using the appropriate duration. That is working quite well, so I think I won't need to try to use an "audio complete" event anyway. But I'm still curious if such an event exists.