import Vue from 'vue' var bgm = { show : false, playing : false, manager : false, control : false, init : function(source, music, title, signer, pic, autoplay) { if (this.manager) { return; } Vue.bgm = { show : false, playing : false, }; if (music) { this.show = true; Vue.bgm.show = true; if (source == 'h5') { this.manager = uni.createInnerAudioContext() this.manager.src = music; this.manager.obeyMuteSwitch = false; this.manager.loop = true; } else { this.manager = uni.getBackgroundAudioManager() this.manager.title = title; this.manager.singer = signer; this.manager.coverImgUrl = pic; this.manager.src = music; this.manager.loop = true; } if (autoplay == 1) { if (source == 'h5') { this.manager.autoplay = true; this.start(); } else { this.start(); } } else { this.stop(); } } else { this.show = false; Vue.bgm.show = false; } }, control : function() { if (this.playing) { this.stop(); } else { this.start(); } }, start : function() { if (this.manager) { if (Vue.control) { var i = 0; for (i in Vue.control) { if (Vue.control[i].load) { Vue.control[i].stop(); } } } this.manager.play(); this.playing = true; Vue.bgm.playing = true; } }, stop : function() { if (this.manager) { this.manager.pause(); this.playing = false; Vue.bgm.playing = false; } } }; export default bgm;