151 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const {
getPlayletManager
} = tt;
Component({
pm: undefined,
data: {
adBanner: null,
videoAlbumId: null,
videoEpisodeId: null,
lockStatus: false
},
ready() {
const pm = getPlayletManager();
this.pm = pm;
pm.onPlay((e) => {
console.log("触发开始播放onPlay回调时间是:", new Date());
this.setData({
lockStatus: false
})
});
pm.onPause((e) => {
console.log('触发暂停播放onPause回调', e)
})
pm.onEnded((e) => {
console.log('触发播放到末尾onEnded回调', e)
})
pm.onError((e) => {
console.log('触发onError回调', e)
})
// 播放进度变化时
pm.onTimeUpdate((e) => {
// 播放进度变化时触发,返回当前播放时间点及视频总时长,单位:秒(s)。event.detail = { currentTime, duration }。
})
pm.onChangeEpisode((e) => {
console.log('切换回调', e)
//当前切换到的集
tt.setStorageSync('currentvideo', {'album_id': e.albumId,episode_id:e.episodeId, seq:e.seq,status: e.status, scene: e.scene});
//当前切换到的解锁集,播放记录用
if(e.status=='free'){
tt.setStorageSync('lastfreevideo', {'album_id': e.albumId,episode_id:e.episodeId, seq:e.seq,status: e.status, scene: e.scene});
}
let lock = false;
// let watchInfo = tt.getStorageSync('watchInfo')
// if(e.scene =='first_play' && watchInfo?.album_id != e.albumId){
// watchInfo = tt.getStorageSync('watchInfo')
// console.log('1')
// }
// const checklock = watchInfo?.isvip != 0 && (watchInfo?.chackpay == 2 || watchInfo?.chackpay == 3)
// console.log(watchInfo)
// console.log(checklock)
// if(e.status =='lock' || (e.scene =='first_play' && checklock)){
if(e.status =='lock'){
lock = true;
}
//更新剧集信息
this.setData({
lockStatus: lock,
videoAlbumId: e.albumId,
videoEpisodeId: e.episodeId,
})
//storage有延时第一次进入锁定剧集时需要刷新
if(e.status =='lock'){
this.emitInfoToParent('change',{album_id: this.data.videoAlbumId,episode_id:this.data.videoEpisodeId})
}
})
pm.onShareSuccess((res) => {
console.log('shareSuccess-uuuu', res);
})
pm.onShareFail((res) => {
console.log('shareFail-uuuu', err);
})
pm.onClickUnlock((e) => {
console.log('aaa')
this.adOpen()
})
this.adLoad()
},
methods: {
//向父组件传值
emitInfoToParent(val:string,data?:any) {
const instance = this.selectOwnerComponent();
instance.emitInfoFromChildren(val,data);
},
adLoad() {
let isAdBanner: any = this.data.adBanner;
// const context: any = tt.createVideoContext(`${videoInfo.id}`);
// this.watchInfo.isvip = 0;
if (!isAdBanner) {
const adBanner: any = tt.createRewardedVideoAd({
adUnitId: "wh0y4vcxsbk7ixwktg",
});
// 监听错误
adBanner.onError((err: any) => {
tt.hideLoading({});
switch (err.errCode) {
case 1004:
// 无合适的广告
break;
default:
// 更多请参考错误码文档
}
});
// 监听视频播放完成
adBanner.onClose((res: any) => {
console.log(res, "resres")
if (res.isEnded) {
this.emitInfoToParent('advunlock',{album_id: this.data.videoAlbumId,episode_id:this.data.videoEpisodeId})
this.setData({
lockStatus: false
})
} else {
tt.showToast({
title: '看完广告方可解锁',
icon: 'none',
duration: 2000
})
}
});
// 预加载资源
adBanner.load();
this.setData({
adBanner: adBanner,
})
}
},
adOpen() {
let adBanner: any = this.data.adBanner;
tt.showToast({
title: `广告加载中...`,
icon: 'none',
});
adBanner.show().then(() => {
// res: any console.log("视频广告展示");
});
},
openPay() {
this.pm.toggleCustomDialog()
},
},
})