时间:2019-05-07 来源:小程序工厂
S***:
模板内容:
JS示例代码:
// page/Demo/index.js
Page({
audioCtx: null,
ind: 0,
coverUrl: "http://image.hhdd.com/books/cover_rec/af2ee001-d7a9-46e5-a2e3-bbc8fc13d433.jpg",
name: "我爸爸",
totalCount: 24,
musicList: [
{
"music": "http://book.hhdd.com/share/51681/pages/54f07360-d3b4-4c16-b3b2-37c83d96eba2.mp3",
"ind": 1
},
{
"music": "",
"ind": 2
},
{
"music": "http://book.hhdd.com/share/51681/pages/a23674c8-e4fa-4dfa-ac95-ebb1fabe301c.mp3",
"ind": 3
},
{
"music": "http://book.hhdd.com/share/51681/pages/98627940-d04d-4446-8b95-bc708831b944.mp3",
"ind": 4
},
{
"music": "http://book.hhdd.com/share/51681/pages/63c2e38f-4ae6-4c78-9ac1-5dc97d3037ff.mp3",
"ind": 5
},
{
"music": "http://book.hhdd.com/share/51681/pages/5e1ec76a-5872-4a8f-b427-7b87ce429bb0.mp3",
"ind": 6
}
],
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
console.log("onReady");
// 背景音频播放器事件列表
const events = {
onCanplay: null,
onPlay: null,
onPause: null,
onStop: null,
onEnded: () => {
this.next();
},
// onTimeUpdate: null,
onPrev: null,
onNext: null,
onError: null,
onWaiting: null,
};
// 获取背景音频控制器
this.audioCtx = wx.getBackgroundAudioManager();
// 添加事件处理
Object.keys(events).forEach(k => {
if (!events[k]) {
this.audioCtx[k]((e) => {
console.log(k, e);
});
return;
}
this.audioCtx[k](events[k]);
});
this.audioPlay();
},
next() {
this.ind++;
if (this.ind >= this.musicList.length) return;
this.audioPlay();
},
audioPlay() {
const options = {
title: `${this.name}-${this.ind + 1}`,
epname: `${this.ind}-${this.totalCount}`,
singer: '咔哒故事',
coverImgUrl: this.coverUrl,
src: this.musicList[this.ind].music
};
// 音频文件不存在,停留1s播放下一首
this.nextTimeout && clearTimeout(this.nextTimeout);
if (!options.src) {
console.log("there is no music on the current page, wait for 1s to play the next page.");
this.nextTimeout = setTimeout(() => {
this.next();
}, 1000);
return;
}
console.log(options);
setTimeout(() => {
Object.keys(options).forEach(k => {
this.audioCtx[k] = options[k];
});
this.audioCtx.play();
}, 1000);
},
audioPause() {
this.audioCtx.pause();
},
audioStop() {
this.audioCtx.stop();
},
audio24() {
this.audioCtx.seek(24);
this.audioCtx.play();
},
audioStart() {
this.audioCtx.seek(0);
}
});
竹***:
问题解决了吗?
微信小程序能进行图像灰度,二值化之类的处理吗?--微信小程序开发