|
@@ -26,6 +26,7 @@ let stl = null
|
|
let setTimeoutObj = null
|
|
let setTimeoutObj = null
|
|
// 录音
|
|
// 录音
|
|
let innerAudioContext = null
|
|
let innerAudioContext = null
|
|
|
|
+// 试听
|
|
let resultAudioContext = null
|
|
let resultAudioContext = null
|
|
/*创建基础引擎*/
|
|
/*创建基础引擎*/
|
|
let wsEngine = aiengine.createWsEngine({});
|
|
let wsEngine = aiengine.createWsEngine({});
|
|
@@ -36,6 +37,8 @@ Page({
|
|
videoInfo: {},
|
|
videoInfo: {},
|
|
currentRow: null,
|
|
currentRow: null,
|
|
state: false,
|
|
state: false,
|
|
|
|
+ // 是否静音播放视频
|
|
|
|
+ muted: false,
|
|
countDown: {
|
|
countDown: {
|
|
state: false,
|
|
state: false,
|
|
num: 3,
|
|
num: 3,
|
|
@@ -71,7 +74,6 @@ Page({
|
|
setReadDetail: 'setReadDetail'
|
|
setReadDetail: 'setReadDetail'
|
|
}
|
|
}
|
|
})
|
|
})
|
|
-
|
|
|
|
// 录音授权
|
|
// 录音授权
|
|
wx.getSetting({
|
|
wx.getSetting({
|
|
success(res) {
|
|
success(res) {
|
|
@@ -106,7 +108,6 @@ Page({
|
|
item.readTime = data[index + 1] ? data[index + 1].time - item.time : ''
|
|
item.readTime = data[index + 1] ? data[index + 1].time - item.time : ''
|
|
return item
|
|
return item
|
|
})
|
|
})
|
|
-
|
|
|
|
this.setData({
|
|
this.setData({
|
|
article: data,
|
|
article: data,
|
|
videoInfo
|
|
videoInfo
|
|
@@ -118,7 +119,7 @@ Page({
|
|
this.videoContext = wx.createVideoContext('myVideo')
|
|
this.videoContext = wx.createVideoContext('myVideo')
|
|
} else {
|
|
} else {
|
|
this.innerAudioContext = wx.createInnerAudioContext();
|
|
this.innerAudioContext = wx.createInnerAudioContext();
|
|
- this.innerAudioContext.src = videoInfo.userRead.audioPath
|
|
|
|
|
|
+ this.innerAudioContext.src = videoInfo.userRead.originVideo
|
|
this.innerAudioContext.onEnded(res => {
|
|
this.innerAudioContext.onEnded(res => {
|
|
this.finishRecord()
|
|
this.finishRecord()
|
|
})
|
|
})
|
|
@@ -141,7 +142,9 @@ Page({
|
|
return
|
|
return
|
|
}
|
|
}
|
|
if (this.data.readingReset) {
|
|
if (this.data.readingReset) {
|
|
- this.stopMediaState()
|
|
|
|
|
|
+ if (!this.data.videoInfo.userReadExtend || this.data.videoInfo.userReadExtend.resourcesType == 0) {
|
|
|
|
+ this.stopMediaState()
|
|
|
|
+ }
|
|
this.clearReset()
|
|
this.clearReset()
|
|
this.getHeight()
|
|
this.getHeight()
|
|
}
|
|
}
|
|
@@ -253,6 +256,7 @@ Page({
|
|
},
|
|
},
|
|
// 结束录制
|
|
// 结束录制
|
|
finishRecord() {
|
|
finishRecord() {
|
|
|
|
+ console.log('触发结束录制了');
|
|
recorderManager.stop();
|
|
recorderManager.stop();
|
|
this.stopMediaState()
|
|
this.stopMediaState()
|
|
clearTimeout(this.setTimeoutObj)
|
|
clearTimeout(this.setTimeoutObj)
|
|
@@ -281,6 +285,8 @@ Page({
|
|
title: this.data.videoInfo.userRead.title,
|
|
title: this.data.videoInfo.userRead.title,
|
|
id: this.data.videoInfo.userRead.exampleId,
|
|
id: this.data.videoInfo.userRead.exampleId,
|
|
coverImg: this.data.videoInfo.userRead.coverImg,
|
|
coverImg: this.data.videoInfo.userRead.coverImg,
|
|
|
|
+ resourcesType: this.data.videoInfo.userReadExtend.resourcesType,
|
|
|
|
+ aBg: this.data.videoInfo.userReadExtend.resourcesType == 1 ? this.data.videoInfo.userReadExtend.backgroundVirtualImg : '',
|
|
originVideo: this.data.videoInfo.userRead.originVideo
|
|
originVideo: this.data.videoInfo.userRead.originVideo
|
|
}
|
|
}
|
|
this.setReadDetail(detail)
|
|
this.setReadDetail(detail)
|
|
@@ -379,9 +385,13 @@ Page({
|
|
},
|
|
},
|
|
videoPlay() {
|
|
videoPlay() {
|
|
if (this.data.readingReset) {
|
|
if (this.data.readingReset) {
|
|
|
|
+ console.log(this.resultAudioContext, 'videoPlay');
|
|
if (this.resultAudioContext) {
|
|
if (this.resultAudioContext) {
|
|
this.resultAudioContext.stop()
|
|
this.resultAudioContext.stop()
|
|
}
|
|
}
|
|
|
|
+ this.setData({
|
|
|
|
+ muted: true
|
|
|
|
+ })
|
|
this.resultAudioContext = wx.createInnerAudioContext();
|
|
this.resultAudioContext = wx.createInnerAudioContext();
|
|
this.resultAudioContext.src = this.data.readDetail.tempFilePath; // 这里可以是录音的临时路径
|
|
this.resultAudioContext.src = this.data.readDetail.tempFilePath; // 这里可以是录音的临时路径
|
|
this.resultAudioContext.play();
|
|
this.resultAudioContext.play();
|
|
@@ -389,6 +399,7 @@ Page({
|
|
},
|
|
},
|
|
// 清除试听状态
|
|
// 清除试听状态
|
|
clearReset() {
|
|
clearReset() {
|
|
|
|
+ console.log('执行了', this.resultAudioContext);
|
|
if (this.resultAudioContext) {
|
|
if (this.resultAudioContext) {
|
|
this.resultAudioContext.stop()
|
|
this.resultAudioContext.stop()
|
|
}
|
|
}
|
|
@@ -398,6 +409,9 @@ Page({
|
|
},
|
|
},
|
|
// 控制视频或音频的播放状态
|
|
// 控制视频或音频的播放状态
|
|
async playMediaState() {
|
|
async playMediaState() {
|
|
|
|
+ this.setData({
|
|
|
|
+ muted: false
|
|
|
|
+ })
|
|
if (!this.data.videoInfo.userReadExtend || this.data.videoInfo.userReadExtend.resourcesType == 0) {
|
|
if (!this.data.videoInfo.userReadExtend || this.data.videoInfo.userReadExtend.resourcesType == 0) {
|
|
this.videoContext.play()
|
|
this.videoContext.play()
|
|
} else {
|
|
} else {
|
|
@@ -442,8 +456,8 @@ Page({
|
|
clearInterval(this.stl)
|
|
clearInterval(this.stl)
|
|
},
|
|
},
|
|
creatShare() {
|
|
creatShare() {
|
|
- let video = this.data.readDetail
|
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
|
+ let video = this.data.videoInfo
|
|
let context = wx.createSelectorQuery();
|
|
let context = wx.createSelectorQuery();
|
|
context
|
|
context
|
|
.select('#share')
|
|
.select('#share')
|
|
@@ -459,53 +473,80 @@ Page({
|
|
ctx.scale(dpr, dpr);
|
|
ctx.scale(dpr, dpr);
|
|
ctx.font = '14px PingFang';
|
|
ctx.font = '14px PingFang';
|
|
let pic = canvas.createImage();
|
|
let pic = canvas.createImage();
|
|
- pic.src = video.coverImg; //可以是本地,也可以是网络图片
|
|
|
|
|
|
+ pic.src = video.userReadExtend && video.userReadExtend.resourcesType == 1 ? video.userReadExtend.backgroundVirtualImg : video.userRead.coverImg;
|
|
pic.onload = () => {
|
|
pic.onload = () => {
|
|
ctx.drawImage(pic, 0, 0, 375, 211);
|
|
ctx.drawImage(pic, 0, 0, 375, 211);
|
|
- let peiyin = canvas.createImage();
|
|
|
|
- peiyin.src = '/static/peiyin.jpg';
|
|
|
|
- peiyin.onload = () => {
|
|
|
|
- ctx.drawImage(peiyin, 0, 211, 375, 89);
|
|
|
|
- //分享
|
|
|
|
- let fx = canvas.createImage();
|
|
|
|
- fx.src = '/static/share.png'
|
|
|
|
- fx.onload = () => {
|
|
|
|
- ctx.drawImage(fx, 12, 220, 20, 20)
|
|
|
|
- ctx.fillText('分享', 36, 238)
|
|
|
|
- // 收藏,一个一个渲染
|
|
|
|
- let sc = canvas.createImage();
|
|
|
|
- sc.src = '/static/no_collect.png'
|
|
|
|
- sc.onload = () => {
|
|
|
|
- ctx.drawImage(sc, 110, 220, 19, 19)
|
|
|
|
- ctx.fillText('收藏', 134, 238)
|
|
|
|
- //点赞
|
|
|
|
- let dz = canvas.createImage();
|
|
|
|
- dz.src = '/static/heart.png'
|
|
|
|
- dz.onload = () => {
|
|
|
|
- ctx.drawImage(dz, 318, 222, 22, 22)
|
|
|
|
- ctx.fillText(0, 254, 238)
|
|
|
|
- // 评论
|
|
|
|
- let pl = canvas.createImage();
|
|
|
|
- pl.src = '/static/comment.png'
|
|
|
|
- pl.onload = () => {
|
|
|
|
- ctx.drawImage(pl, 228, 222, 22, 22)
|
|
|
|
- ctx.fillText(0, 340, 238)
|
|
|
|
- setTimeout(() => {
|
|
|
|
- wx.canvasToTempFilePath({
|
|
|
|
- canvas: canvas,
|
|
|
|
- success(res) {
|
|
|
|
- resolve({
|
|
|
|
- title: '请欣赏我的课文朗读作品,点赞+评论。',
|
|
|
|
- path: `/pages/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
|
|
|
|
- imageUrl: res.tempFilePath
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- fail(res) {
|
|
|
|
- reject()
|
|
|
|
- }
|
|
|
|
- }, this)
|
|
|
|
- }, 500)
|
|
|
|
- }
|
|
|
|
|
|
+ if (video.userReadExtend.resourcesType == 1) {
|
|
|
|
+ let aBg = canvas.createImage();
|
|
|
|
+ aBg.src = '/static/shareAudioBg.png';
|
|
|
|
+ aBg.onload = () => {
|
|
|
|
+ ctx.drawImage(aBg, 127.5, 38, 120, 120);
|
|
|
|
+ let rate = 0.5
|
|
|
|
+ ctx.arc(
|
|
|
|
+ Math.floor(375 * rate),
|
|
|
|
+ 98,
|
|
|
|
+ Math.floor(100 * rate),
|
|
|
|
+ 0,
|
|
|
|
+ 2 * Math.PI
|
|
|
|
+ );
|
|
|
|
+ ctx.clip() //裁剪
|
|
|
|
+ let coverImg = canvas.createImage();
|
|
|
|
+ coverImg.src = video.userRead.coverImg;
|
|
|
|
+ coverImg.onload = () => {
|
|
|
|
+ ctx.drawImage( //定位在圆圈范围内便会出现
|
|
|
|
+ coverImg, //图片暂存路径
|
|
|
|
+ 129, 42,
|
|
|
|
+ 110, 110,
|
|
|
|
+ );
|
|
|
|
+ ctx.restore()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ let peiyin = canvas.createImage();
|
|
|
|
+ peiyin.src = '/static/peiyin.jpg';
|
|
|
|
+ peiyin.onload = () => {
|
|
|
|
+ ctx.drawImage(peiyin, 0, 211, 375, 89);
|
|
|
|
+ //分享
|
|
|
|
+ let fx = canvas.createImage();
|
|
|
|
+ fx.src = '/static/share.png'
|
|
|
|
+ fx.onload = () => {
|
|
|
|
+ ctx.drawImage(fx, 12, 220, 20, 20)
|
|
|
|
+ ctx.fillText('分享', 36, 238)
|
|
|
|
+ // 收藏,一个一个渲染
|
|
|
|
+ let sc = canvas.createImage();
|
|
|
|
+ sc.src = '/static/no_collect.png'
|
|
|
|
+ sc.onload = () => {
|
|
|
|
+ ctx.drawImage(sc, 110, 220, 19, 19)
|
|
|
|
+ ctx.fillText('收藏', 134, 238)
|
|
|
|
+ //点赞
|
|
|
|
+ let dz = canvas.createImage();
|
|
|
|
+ dz.src = '/static/heart.png'
|
|
|
|
+ dz.onload = () => {
|
|
|
|
+ ctx.drawImage(dz, 318, 222, 22, 22)
|
|
|
|
+ ctx.fillText(0, 254, 238)
|
|
|
|
+ // 评论
|
|
|
|
+ let pl = canvas.createImage();
|
|
|
|
+ pl.src = '/static/comment.png'
|
|
|
|
+ pl.onload = () => {
|
|
|
|
+ ctx.drawImage(pl, 228, 222, 22, 22)
|
|
|
|
+ ctx.fillText(0, 340, 238)
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
|
+ canvas: canvas,
|
|
|
|
+ success(res) {
|
|
|
|
+ console.log(wx.getStorageSync('shareVideoId'));
|
|
|
|
+ resolve({
|
|
|
|
+ title: '我的新作品发布啦,快来捧场点赞!',
|
|
|
|
+ path: `/pages/pkPage/index?videoId=${wx.getStorageSync('shareVideoId')}&uid=${wx.getStorageSync('uid')}`,
|
|
|
|
+ imageUrl: res.tempFilePath
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ fail(res) {
|
|
|
|
+ reject()
|
|
|
|
+ }
|
|
|
|
+ }, this)
|
|
|
|
+ }, 500)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|