增加抖音官方播放器的完播推荐和挽留推荐
This commit is contained in:
parent
a74091129b
commit
dc22308178
@ -1,3 +1,4 @@
|
||||
import {httpRequest} from "../../utils/httpReques";
|
||||
|
||||
const {
|
||||
getPlayletManager
|
||||
@ -8,7 +9,9 @@ Component({
|
||||
adBanner: null,
|
||||
videoAlbumId: null,
|
||||
videoEpisodeId: null,
|
||||
lockStatus: false
|
||||
lockStatus: false,
|
||||
hasSetBackRecommend: false,
|
||||
hasSetRecommend: false,
|
||||
},
|
||||
ready() {
|
||||
const pm = getPlayletManager();
|
||||
@ -32,6 +35,7 @@ Component({
|
||||
|
||||
// 播放进度变化时
|
||||
pm.onTimeUpdate((e) => {
|
||||
this.playTimeListener(e);
|
||||
// 播放进度变化时触发,返回当前播放时间点及视频总时长,单位:秒(s)。event.detail = { currentTime, duration }。
|
||||
})
|
||||
|
||||
@ -62,8 +66,9 @@ Component({
|
||||
videoAlbumId: e.albumId,
|
||||
videoEpisodeId: e.episodeId,
|
||||
})
|
||||
//storage有延时,第一次进入锁定剧集时,需要刷新
|
||||
if(e.status =='lock'){
|
||||
// 在切换到锁定的集 或者 切换了剧(官方完播推荐) 之后,需要刷新数据
|
||||
const watchInfo = tt.getStorageSync('watchInfo')
|
||||
if(e.status =='lock' || e.album_id != watchInfo.album_id){
|
||||
this.emitInfoToParent('change',{album_id: this.data.videoAlbumId,episode_id:this.data.videoEpisodeId})
|
||||
}
|
||||
})
|
||||
@ -147,5 +152,84 @@ Component({
|
||||
openPay() {
|
||||
this.pm.toggleCustomDialog()
|
||||
},
|
||||
//播放进度条监听
|
||||
playTimeListener(e) {
|
||||
// console.log('eee',e);
|
||||
// 返回推荐-触发
|
||||
if (e.currentTime >= 10 && !this.data.hasSetBackRecommend && tt.canIUse('back-recommend')) {
|
||||
console.log('backReCommend')
|
||||
this.pm.setRecommendConfig({
|
||||
entryType: 2,
|
||||
switchStatus: true,
|
||||
});
|
||||
this.setData({
|
||||
hasSetBackRecommend: true
|
||||
})
|
||||
}
|
||||
// 完播推荐-触发
|
||||
if (e.duration - e.currentTime <= 10 && !this.data.hasSetRecommend) {
|
||||
console.log('reCommend')
|
||||
this.reCommend();
|
||||
this.setData({
|
||||
hasSetRecommend: true
|
||||
})
|
||||
}
|
||||
},
|
||||
//完播推荐
|
||||
async reCommend(){
|
||||
const chapterList = tt.getStorageSync('chapterList');
|
||||
const currentVideo = tt.getStorageSync('currentvideo');
|
||||
if(!!chapterList && !!currentVideo) {
|
||||
const total = this.countChapterListTotal();
|
||||
if (currentVideo.seq === total) {
|
||||
let albumId = await this.setNextPart(currentVideo)
|
||||
// albumId = "7446342228814856730"
|
||||
let configItem = {
|
||||
entryType: 1,
|
||||
switchStatus: true,
|
||||
}
|
||||
if(albumId){
|
||||
configItem = {
|
||||
...configItem,
|
||||
data: {
|
||||
albumId: albumId,
|
||||
seq: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
this.pm.setRecommendConfig(configItem);
|
||||
}
|
||||
}
|
||||
},
|
||||
//原来的拼剧接口
|
||||
setNextPart(currentVideo){
|
||||
return new Promise(resolve=>{
|
||||
httpRequest('/getNextPart', 'post', {
|
||||
album_id: currentVideo.album_id,
|
||||
episode_id: currentVideo.episode_id
|
||||
}).then((res) => {
|
||||
if (res.album_id) {
|
||||
resolve(res.album_id)
|
||||
}
|
||||
resolve()
|
||||
}).catch(e=>{
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
},
|
||||
//计算总集数
|
||||
countChapterListTotal() {
|
||||
let total = 0;
|
||||
const chapterList = tt.getStorageSync('chapterList');
|
||||
if(!chapterList){
|
||||
return total;
|
||||
}
|
||||
let dataList = [...chapterList.freeList,...chapterList.lockList]
|
||||
dataList.sort((a, b) => {return +b.end_episode_no - +a.end_episode_no})
|
||||
if(dataList.length>0){
|
||||
total = dataList[0].end_episode_no
|
||||
}
|
||||
return total;
|
||||
},
|
||||
},
|
||||
})
|
@ -145,6 +145,8 @@ PlayletExtension({
|
||||
watchInfo: _watchinfo
|
||||
})
|
||||
tt.setStorageSync('watchInfo', _watchinfo);
|
||||
const _chapterList = { freeList: _freeList, lockList: _lockList }
|
||||
tt.setStorageSync('chapterList', _chapterList);
|
||||
},
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user