我正试图为phonegap应用程序组装一张音频地图。我想要构造简单的句子来创造方向。
为了缩小范围,我有一个数组的音频元素,我想要连续播放,以执行音频导航。例如:
// playList[0].play --> "You are coming from the"
// playList[1].play --> "Reptile House"
// playList[2].play --> "(half-second pause as sentence period...)"
// playlist[3].play --> "Please select a destination from the list on the left."
在这篇文章的底部是我一直在玩的简化代码,但没有取得多大成功。我总是犯错误。在建议使用jplayer或其他系统之前,在我看来,这些系统更适合于播放具有阻止它们的能力的歌曲。我不需要一个完整的jplayer或其他风格的界面。我只需要人们按下按钮,这样他们就可以通过音频地图系统被引导。我一直在控制台中得到这个错误:
Uncaught TypeError: Object #selectionFrom has no method 'play' audio-map.js:142
(anonymous function) audio-map.js:142
jQuery.event.dispatch jquery-1.9.1.js:3074
jQuery.event.add.elemData.handle jquery-1.9.1.js:2750
我尝试过将数组作为元素ID和只是变量。
var playList= ["#selectionFrom","#playReptileHouse","#play500msPause","#selectDestination"];
var playList= ["selectionFrom","playReptileHouse","play500msPause","selectDestination"];
如果能提供任何帮助我会很高兴的。以下是简化的脚本:
$(document).ready(function() {
var playZooEntrance = document.createElement('audio');
playZooEntrance.setAttribute('src', 'assets/audio/playZooEntrance.mp3');
playZooEntrance.setAttribute('id', 'playZooEntrance');
document.body.appendChild(playZooEntrance);
var playReptileHouse = document.createElement('audio');
playReptileHouse.setAttribute('src', 'assets/audio/playReptileHouse.mp3');
playReptileHouse.setAttribute('id', 'playReptileHouse');
document.body.appendChild(playReptileHouse);
var selectionFrom = document.createElement('audio');
selectionFrom.setAttribute('src', 'assets/audio/selectionFrom.mp3');
selectionFrom.setAttribute('id', 'selectionFrom');
document.body.appendChild(selectionFrom);
var selectDestination = document.createElement('audio');
selectDestination.setAttribute('src', 'assets/audio/selectDestination.mp3');
selectDestination.setAttribute('id', 'selectDestination');
document.body.appendChild(selectDestination);
var play500msPause = document.createElement('audio');
play500msPause.setAttribute('src', 'assets/audio/play500msPause.mp3');
play500msPause.setAttribute('id', 'play500msPause');
document.body.appendChild(play500msPause);
$('#selected_from').click(function() { // On the press of a button...
var playList= ["selectionFrom","playReptileHouse","play500msPause","selectDestination"];
var i;
for (i = 0; i < playList.length; ++i) {
console.log(playList[i]);
playList[i].play();
playList[i].setAttribute('ended',function(){/* next i??? */});
}
});
// Play this consecutively...
// playList[0].play --> "You're coming from the"
// playList[1].play --> "Reptile House"
// playList[2].play --> "(half-second pause)"
// playlist[3].play --> "Please select a destination from the list on the left."
});
发布于 2013-11-30 17:00:14
似乎您犯了一个类型错误:当您想要获得具有该id的元素时,您需要一个字符串('SelectionFrom')来播放。
因此,您可以在创建元素时将元素预存储在数组或对象中,或者使用jquery ($('#'+playList[i]
)通过id查找元素。
https://stackoverflow.com/questions/20302897
复制相似问题