2012-12-30 52 views
0

嘗試將停止功能的JavaScript添加到音頻對象這樣添加功能,音頻對象

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

可以像這樣使用

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

作品在谷歌瀏覽器,但不能在Firefox 。有任何想法嗎 ?

回答

1

使用new Audio創建元素將創建一個元素,其原型爲HTMLAudioElement.prototype。按照規範,這應該與Audio.prototype相同,但我相信Firefox並未實現WebIDL的這一部分。

無論如何,在HTMLAudioElement.prototype上設置你的東西應該可以在兩種瀏覽器中工作,我想。

+0

是的,這在鉻和Firefox的作​​品。謝謝!! –