123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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;
|