Commit abc1c9c8 authored by wildfirecode13's avatar wildfirecode13

1

parent 1e07b1a4
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import resList from '../../resconfig/resList'; import resList from '../../resconfig/resList';
import API from '../../api'; import API from '../../api';
import { SHARE_CONFIG } from '/tbcc-sdk/lib/constants'; import { SHARE_CONFIG } from '/tbcc-sdk/lib/constants';
import playBgMusic from '/utils/playBgMusic';
const app = getApp(); const app = getApp();
const { tbcc } = app; const { tbcc } = app;
const { commonToast, getAuthUserInfo, navigateToOutside } = tbcc.tb; const { commonToast, getAuthUserInfo, navigateToOutside } = tbcc.tb;
...@@ -66,6 +67,8 @@ Page({ ...@@ -66,6 +67,8 @@ Page({
this.getUserCredits(); this.getUserCredits();
this.getOrderList(); this.getOrderList();
// this.screenAdapt(); // this.screenAdapt();
this.addMusic();
}, },
// screenAdapt(){ // screenAdapt(){
...@@ -469,5 +472,13 @@ Page({ ...@@ -469,5 +472,13 @@ Page({
// console.log(SHARE_CONFIG) // console.log(SHARE_CONFIG)
return SHARE_CONFIG; return SHARE_CONFIG;
}, },
async addMusic(){
const resultSrc = await app.cloud.file.getTempFileURL({
fileId: 'cloud://C7A066C702682E94326284DF8A2975CC//FILA_building_loop.mp3'
});
let musicUrl = null;
if (resultSrc[0]) musicUrl = resultSrc[0].url;
playBgMusic(true,musicUrl)
console.log('fuck music')
}
}); });
\ No newline at end of file
class AudioModel {
// isOn = false;
constructor(opts = {}) {
const { src } = opts;
if (!src) {
console.error('请输入音频链接');
return false;
}
try {
const innerAudioContext = my.createInnerAudioContext();
Object.keys(opts).forEach(item => {
innerAudioContext[item] = opts[item];
});
// this.isOn = opts.autoplay;
// innerAudioContext.isOn = opts.autoplay;
return innerAudioContext;
} catch (e) {
console.error('当前版本不支持音频');
}
}
};
const createAudio = opts => {
const audioInstance = new AudioModel(opts)
return audioInstance;
};
let bgs = {
}
const playBgMusic = (isOn, src) => {//待测试
for (let k in bgs) {
if (bgs[k].isOn) {
bgs[k].stop();
}
// bgs[k].isOn = false; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
const key = src;
if (isOn) {
if (!bgs[key]) {
bgs[key] = createAudio({
src: src,
autoplay: true,
loop: false /// TODO 暂时无效?2020.08.12 目前有效,但stop后还会跑数据,导致到音频结束到时间又自动播放
});
bgs[key].onPlay(() => {
bgs[key].isOn = true;
});
bgs[key].onStop(() => {
bgs[key].isOn = false;
});
/// TODO监听结束,因为loop无效 2020.08.12 loop有效,这个操作是为了解决stop之后还会跑音频数据的问题
bgs[key].onEnded(() => {
if (bgs[key].isOn) { // 判断自己记录的开关
bgs[key].play();
// bgs[key].isOn = true;
}
});
bgs[key].play(); // 安卓有时候autoplay好像莫得用
// console.log(src)
// bgs[key].isOn = true; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
} else {
bgs[key].play();
// bgs[key].isOn = true; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
} else {
if (bgs[key]) {
// bgs[key].pause(); /// pause 垃圾,不能用
bgs[key].stop();
// bgs[key].isOn = false; /// TODO 自己记一个开关,因为淘宝的玩意stop之后虽然听不到,但还是在播放,会触发loop播放和onEnded事件
}
}
}
export default playBgMusic
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment