Detect finish of embedded audio [RESOLVED]

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Detect finish of embedded audio [RESOLVED]

Post 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.]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Detect finish of embedded audio

Post by Weirdan »

Can you post the source code of that DHTMLSound() function? I'm pretty sure it's not one of browser-provided functions.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Detect finish of embedded audio

Post 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.
Post Reply