Prashant Pugalia
Prashant Pugalia

Reputation: 1101

Adding functions to Audio object

Trying to add a stop function to the Audio object in javascript like this

//Give the Audio object a stop function
Audio.prototype.stop = function()
{
this.pause();
this.currentTime = 0.0;
}

can be used like this

var aud = new Audio();
aud.src = 'background.ogg';
aud.play();
aud.stop();

Works in Google Chrome, but not in firefox. any ideas ?

Upvotes: 0

Views: 348

Answers (1)

Boris Zbarsky
Boris Zbarsky

Reputation: 35064

Creating an element with new Audio creates an element whose prototype is HTMLAudioElement.prototype. Per spec this should be the same object as Audio.prototype, but I believe Firefox doesn't implement that part of WebIDL yet.

In any case, setting your stuff on HTMLAudioElement.prototype should work in both browsers, I would think.

Upvotes: 1

Related Questions