1

我正在尝试为 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."
});
4

1 回答 1

1

看来您犯了一个类型错误:当您要获取具有该 ID 的元素时,您要求播放一个字符串 ('SelectionFrom')。
因此,您可以在创建元素时将元素预先存储在数组或对象中,或者使用 jquery ( $('#'+playList[i]) 通过 id 查找它们。

于 2013-11-30T17:00:14.990 回答