首页 文章

我正在寻找Cordova插件 - 媒体工作示例(演示)[关闭]

提问于
浏览
-2

我在cordova-plugin-media的npm / github文档中找到了一个例子:
https://www.npmjs.com/package/cordova-plugin-media
https://github.com/apache/cordova-plugin-media
我也试图实现这两个:
Play sound on Phonegap app for Android
audio not working with phoneGap

到目前为止没有运气 . 我在哪里可以找到最新的复制和粘贴示例?十分感谢!

(Cordova版本5.1.1,我通过 cordova plugin add cordova-plugin-media 安装插件)

1 回答

  • 2

    您的index.js文件应该如下所示,并在index.html中删除自己编写的javascript:

    var app = {
        initialize: function() {
            this.bindEvents();
        },
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
    
            var myMedia = new Media("http://www.noiseaddicts.com/samples_1w72b820/3926.mp3")
            myMedia.play({ playAudioWhenScreenIsLocked : false })
    
        },
        receivedEvent: function(id) {
            var parentElement = document.getElementById(id);
            var listeningElement = parentElement.querySelector('.listening');
            var receivedElement = parentElement.querySelector('.received');
    
            listeningElement.setAttribute('style', 'display:none;');
            receivedElement.setAttribute('style', 'display:block;');
    
            console.log('Received Event: ' + id);
        }
    };
    
    app.initialize();
    

相关问题