【问题标题】:Phonegap play audio with Media pluginPhonegap 使用 Media 插件播放音频
【发布时间】:2015-11-08 21:48:55
【问题描述】:

我正在使用 phonegap 中的媒体在我的 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') 后,我收到了

Uncaught ReferenceError: Media is not defined index.js:54

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

【问题讨论】:

  • 在设备就绪事件后调用函数playsnd(url)它应该可以工作

标签: javascript android cordova audio


【解决方案1】:

您必须等待ondeviceready 事件。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多