|
|
@@ -19,13 +19,74 @@ Component({
|
|
|
},
|
|
|
lifetimes: {
|
|
|
attached() {
|
|
|
+ this.ensureInnerAudioOption();
|
|
|
},
|
|
|
detached() {
|
|
|
this.stopSunRotation();
|
|
|
this.stopTiger();
|
|
|
+ this.stopBgm();
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ ensureInnerAudioOption() {
|
|
|
+ if (this._innerAudioOptionInited) return;
|
|
|
+ this._innerAudioOptionInited = true;
|
|
|
+ if (!wx || typeof wx.setInnerAudioOption !== 'function') return;
|
|
|
+ try {
|
|
|
+ wx.setInnerAudioOption({ obeyMuteSwitch: false });
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ },
|
|
|
+ startBgm() {
|
|
|
+ this.bgmShouldPlay = true;
|
|
|
+ if (this.bgmCtx) {
|
|
|
+ try {
|
|
|
+ this.bgmCtx.play();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.ensureInnerAudioOption();
|
|
|
+ if (!wx || typeof wx.createInnerAudioContext !== 'function') return;
|
|
|
+
|
|
|
+ const bgmCtx = wx.createInnerAudioContext();
|
|
|
+ bgmCtx.src = 'https://ossxiaoan.4dage.com/hq-eduction-vr/bg.mp3';
|
|
|
+ bgmCtx.loop = true;
|
|
|
+ bgmCtx.volume = 0.25;
|
|
|
+
|
|
|
+ const keepAlive = () => {
|
|
|
+ if (!this.bgmShouldPlay) return;
|
|
|
+ if (!this.bgmCtx) return;
|
|
|
+ try {
|
|
|
+ bgmCtx.play();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ bgmCtx.onStop(keepAlive);
|
|
|
+ bgmCtx.onPause(keepAlive);
|
|
|
+ bgmCtx.onEnded(keepAlive);
|
|
|
+
|
|
|
+ this.bgmCtx = bgmCtx;
|
|
|
+ try {
|
|
|
+ bgmCtx.play();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ },
|
|
|
+ stopBgm() {
|
|
|
+ this.bgmShouldPlay = false;
|
|
|
+ if (!this.bgmCtx) return;
|
|
|
+ try {
|
|
|
+ this.bgmCtx.stop();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ this.bgmCtx.destroy();
|
|
|
+ } catch (e) {
|
|
|
+ }
|
|
|
+ this.bgmCtx = null;
|
|
|
+ },
|
|
|
emitLoadState(extra) {
|
|
|
const payload = Object.assign({
|
|
|
arReady: !!this.data.arReady,
|
|
|
@@ -161,6 +222,7 @@ Component({
|
|
|
if (!this.data.item1Loaded) {
|
|
|
this.setData({ item1Loaded: true }, () => this.emitLoadState());
|
|
|
}
|
|
|
+ this.startBgm();
|
|
|
this.tryStartEntryAnimation();
|
|
|
},
|
|
|
handleItem2Loaded({ detail }) {
|
|
|
@@ -663,6 +725,7 @@ Component({
|
|
|
},
|
|
|
prepareTigerAudio() {
|
|
|
if (this.tigerAudioCtx || this.tigerAudioPreparing) return;
|
|
|
+ this.ensureInnerAudioOption();
|
|
|
const url = 'https://ossxiaoan.4dage.com/hq-eduction-vr/tiger/tiger.mp3';
|
|
|
|
|
|
this.tigerAudioPrepared = false;
|
|
|
@@ -671,6 +734,7 @@ Component({
|
|
|
this.tigerAudioPreparing = true;
|
|
|
|
|
|
const createAudioCtx = (src) => {
|
|
|
+ this.ensureInnerAudioOption();
|
|
|
const audioCtx = wx.createInnerAudioContext();
|
|
|
audioCtx.src = src;
|
|
|
audioCtx.loop = false;
|
|
|
@@ -849,6 +913,7 @@ Component({
|
|
|
} else {
|
|
|
const audioUrl = 'https://houseoss.4dkankan.com/project/hq-eduction-vr/public/%E5%AE%89%E5%BE%B7%E7%83%88.mp3';
|
|
|
if (!this.audioCtx) {
|
|
|
+ this.ensureInnerAudioOption();
|
|
|
const audioCtx = wx.createInnerAudioContext();
|
|
|
audioCtx.src = audioUrl;
|
|
|
audioCtx.play();
|