在cordova接收通知时播放自定义歌曲

时间:2017-06-19 12:06:14

标签: android cordova plugins media

我添加了插件 cordova-plugin-media

    db.push.onNotificationGCM = function(e) {

    var myMedia = new Media("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3")
myMedia.play({ numberOfLoops: 2 })

        switch (e.event) {
            case 'registered':
                if (e.regid.length > 0) {
                    db.push.devicetoken = e.regid;
                    var data_to_send = {
                        devicetoken: db.push.devicetoken,
                        platform: 'android'
                    };
                    db.push.register_push(data_to_send);
                }
                break;
            case 'message':
                if (e.foreground) {
                    app.t(e.payload.message);
                    db.notifications.data = TAFFY();
                } else {
                    db.push.deeplink = e.payload.deeplink;
                    if (e.coldstart) {} else {
                        db.notifications.data = TAFFY();
                        db.push.gotoDeeplink();
                    }
                }
                break;
            case 'error':
                break;
            default:
                break;
        }
    }

问题:

Media is not defined

1 个答案:

答案 0 :(得分:0)

找到答案,

实际上由于版本问题,插件最新版本不支持Android版本6

我的项目支持的插件:

cordova plugin add cordova-plugin-media@2.2.0

为我工作!!!