瀏覽代碼

修改头条的音频播放

tang biao 5 年之前
父節點
當前提交
0bedf44812
共有 1 個文件被更改,包括 91 次插入6 次删除
  1. 91 6
      assets/scripts/utils/AudioMng.js

+ 91 - 6
assets/scripts/utils/AudioMng.js

@@ -141,7 +141,21 @@ cc.Class({
      */
     playClickButton () {
         if (!this.soundEffectOpen) { return }
-        cc.audioEngine.play(this.buttonClickAudio, false, this.volume);
+        if (window.tt != undefined) {
+            // if (this.playClickButtonAudioContext != null && this.playClickButtonAudioContext != undefined) {
+            //     // this.playClickButtonAudioContext.destory();
+            // }
+            this.playClickButtonAudioContext = tt.createInnerAudioContext();
+            this.playClickButtonAudioContext.autoplay = false;
+            this.playClickButtonAudioContext.src = 'https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test/sheet/buttonClick.mp3';
+            this.playClickButtonAudioContext.play();
+            // this.playClickButtonAudioContext.onEnded(() => {
+            //     this.playClickButtonAudioContext.destory();
+            //     this.playClickButtonAudioContext = null;
+            // })
+        } else {
+            cc.audioEngine.play(this.buttonClickAudio, false, this.volume);
+        }
     },
 
     /**
@@ -149,7 +163,22 @@ cc.Class({
      */
     playGetAward () {
         if (!this.soundEffectOpen) { return }
-        cc.audioEngine.play(this.getAwardAudio, false, this.volume);
+        if (window.tt != undefined) {
+            // if (this.playGetAwardAudioContext != null && this.playGetAwardAudioContext != undefined) {
+            //     // this.playGetAwardAudioContext.destory();
+            // }
+            this.playGetAwardAudioContext = tt.createInnerAudioContext();
+            this.playGetAwardAudioContext.autoplay = false;
+            this.playGetAwardAudioContext.src = 'https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test/sheet/getAward.mp3';
+            this.playGetAwardAudioContext.play();
+            // this.playGetAwardAudioContext.onEnded(() => {
+            //     this.playGetAwardAudioContext.destory();
+            //     this.playGetAwardAudioContext = null;
+            // })
+        } else {
+            cc.audioEngine.play(this.getAwardAudio, false, this.volume);
+
+        }
     },
 
     /**
@@ -157,7 +186,21 @@ cc.Class({
      */
     playUpdateBuilding () {
         if (!this.soundEffectOpen) { return }
-        cc.audioEngine.play(this.updateBuildingAudio, false, this.volume);
+        if (window.tt != undefined) {
+            // if (this.updateBuildingAudioContext != undefined && this.updateBuildingAudioContext != null) {
+            //     // this.updateBuildingAudioContext.destory();
+            // }
+            this.updateBuildingAudioContext = tt.createInnerAudioContext();
+            this.updateBuildingAudioContext.autoplay = false;
+            this.updateBuildingAudioContext.src = 'https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test/sheet/updateBuilding.mp3';
+            this.updateBuildingAudioContext.play();
+            // this.updateBuildingAudioContext.onEnded(() => {
+            //     this.updateBuildingAudioContext.destory();
+            //     this.updateBuildingAudioContext = null;
+            // })
+        } else {
+            cc.audioEngine.play(this.updateBuildingAudio, false, this.volume);
+        }
     },
 
     /**
@@ -165,7 +208,21 @@ cc.Class({
      */
     playClickCat () {
         if (!this.soundEffectOpen) { return }
-        cc.audioEngine.play(this.clickCatAudio, false, this.volume);
+        if (window.tt != undefined) {
+            // if (this.innerAudioContext != undefined && this.innerAudioContext != null) {
+            //     // this.innerAudioContext.destory();
+            // }
+            this.innerAudioContext = tt.createInnerAudioContext();
+            this.innerAudioContext.autoplay = false;
+            this.innerAudioContext.src = 'https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test/sheet/clickCat.mp3';
+            this.innerAudioContext.play();
+            // this.innerAudioContext.onEnded(() => {
+            //     this.innerAudioContext.destory();
+            //     this.innerAudioContext = null;
+            // })
+        } else {
+            cc.audioEngine.play(this.clickCatAudio, false, this.volume)
+        }
     },
 
     /**
@@ -173,7 +230,21 @@ cc.Class({
      */
     playGetDraw () {
         if (!this.soundEffectOpen) { return }
-        cc.audioEngine.play(this.getDrawAudio, false, this.volume);
+        if (window.tt != undefined) {
+            // if (this.getDrawAudioContext != undefined && this.getDrawAudioContext != null) {
+            //     // this.getDrawAudioContext.destory();
+            // }
+            this.getDrawAudioContext = tt.createInnerAudioContext();
+            this.getDrawAudioContext.autoplay = false;
+            this.getDrawAudioContext.src = 'https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test/sheet/getDraw.mp3';
+            this.getDrawAudioContext.play();
+            // this.getDrawAudioContext.onEnded(() => {
+            //     this.getDrawAudioContext.destory();
+            //     this.getDrawAudioContext = null;
+            // })        
+        } else {
+            cc.audioEngine.play(this.getDrawAudio, false, this.volume);
+        }
     },
 
     /**
@@ -181,7 +252,21 @@ cc.Class({
      */
     playGetStar () {
         if (!this.soundEffectOpen) { return }
-        cc.audioEngine.play(this.getStarAudio, false, this.volume);
+        if (window.tt != undefined) {
+            // if (this.playGetStarAudioContext != undefined && this.playGetStarAudioContext != null) {
+            //     // this.playGetStarAudioContext.destory();
+            // }
+            this.playGetStarAudioContext = tt.createInnerAudioContext();
+            this.playGetStarAudioContext.autoplay = false;
+            this.playGetStarAudioContext.src = 'https://pub.dwstatic.com/wxgame/taptapstar_toutiao_test/sheet/getStar.mp3';
+            this.playGetStarAudioContext.play();
+            // this.playGetStarAudioContext.onEnded(() => {
+            //     this.playGetStarAudioContext.destory();
+            //     this.playGetStarAudioContext = null;
+            // })
+        } else {
+            cc.audioEngine.play(this.getStarAudio, false, this.volume);
+        }
     },
 
     /**