105 lines
2.5 KiB
TypeScript
105 lines
2.5 KiB
TypeScript
|
||
const {
|
||
getPlayletManager
|
||
} = tt;
|
||
Component({
|
||
pm: undefined,
|
||
data: {
|
||
adBanner: null,
|
||
videoAlbumId: null,
|
||
videoEpisodeId: null,
|
||
},
|
||
ready() {
|
||
const pm = getPlayletManager();
|
||
this.pm = pm;
|
||
|
||
pm.onPlay((e) => {
|
||
console.log("触发开始播放onPlay回调,时间是:", new Date());
|
||
});
|
||
pm.onPause((e) => {
|
||
console.error('触发暂停播放onPause回调', e)
|
||
})
|
||
pm.onEnded((e) => {
|
||
console.error('触发播放到末尾onEnded回调', e)
|
||
})
|
||
pm.onError((e) => {
|
||
console.error('触发onError回调', e)
|
||
})
|
||
|
||
// 播放进度变化时
|
||
pm.onTimeUpdate((e) => {
|
||
// 播放进度变化时触发,返回当前播放时间点及视频总时长,单位:秒(s)。event.detail = { currentTime, duration }。
|
||
})
|
||
|
||
pm.onChangeEpisode((e) => {
|
||
//更新剧集信息
|
||
this.setData({
|
||
videoAlbumId: e.albumId,
|
||
videoEpisodeId: e.episodeId,
|
||
})
|
||
})
|
||
|
||
pm.onShareSuccess((res) => {
|
||
console.log('shareSuccess-uuuu', res);
|
||
})
|
||
pm.onShareFail((res) => {
|
||
console.log('shareFail-uuuu', err);
|
||
})
|
||
|
||
pm.onClickUnlock((e) => {
|
||
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})
|
||
} else {
|
||
tt.showToast({
|
||
title: '看完广告方可解锁',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
});
|
||
|
||
// 预加载资源
|
||
adBanner.load();
|
||
this.setData({
|
||
adBanner: adBanner,
|
||
})
|
||
}
|
||
},
|
||
}
|
||
}) |