我正在开发一个网络应用,我需要播放单词和句子音频文件。我使用骨干来从服务器获取和呈现内容。音频文件存在于S3上。当渲染内容时,我播放单词音频文件,然后播放句子音频文件。我也有一个按钮,所以可以重放单词和句子音频。
我的问题是Firefox在初始播放后不会重播音频文件。调用playWord
和playSentence
时,没有任何反应。 Safari和Chrome中的代码字很好。
events: {
"click a#play-sentence": "playSentence",
"click a#play-word": "playWord"
},
// render markup when model has synced with server
render: function() {
this.$el.html(this.template({ exam: this.model }));
this.cacheMedia();
return this;
},
// save audio objects. play word then sentence
cacheMedia: function() {
this.audioWord = this.$el.find('#audioWord').get(0);
this.audioSentence = this.$el.find('#audioSentence').get(0);
this.audioWord.addEventListener('ended', function(){
this.currentTime = 0;
}, false);
this.audioSentence.addEventListener('ended', function(){
this.currentTime = 0;
}, false);
var view = this;
var playSentence = function() {
view.audioSentence.play();
view.audioWord.removeEventListener('ended', playSentence);
};
this.audioWord.addEventListener('ended', playSentence);
this.audioWord.play();
},
// play sentence audio
playSentence: function(e) {
e.preventDefault();
this.audioWord.pause();
this.audioWord.currentTime = 0;
this.audioSentence.play();
},
// play word audio
playWord: function(e) {
e.preventDefault();
this.audioSentence.pause();
this.audioSentence.currentTime = 0;
this.audioWord.play();
}
答案 0 :(得分:0)
您需要做的就是在两种情况下都致电.load()
,即playWord()
只需要this.audioWord.load();
而playSentence()
只需要this.audioSentence.load()
;.