首页 文章

Phonegap使用Media插件播放音频

提问于
浏览
0

我正在使用来自phonegap的Media在我的APP中播放一些音频 .

function playSnd(url) {
    // Play the audio file at url
    var my_media = new Media(url,
        // success callback
        function() {
            console.log("playAudio():Audio Success");
        },
        // error callback
        function(err) {
            console.log("playAudio():Audio Error: " + err);
        });

    // Play audio
    my_media.play();
}

在我的控制台中调用playSnd('audio.mp3')之后我就回忆道

未捕获的ReferenceError:媒体未定义index.js:54

LE:我安装了https://github.com/apache/cordova-plugin-media .

1 回答

  • 0

    你必须等待 ondeviceready 事件 .

    document.addEventListener('deviceready', function () {/* your code goes here */});

相关问题