-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBitmovinYospacePlayerPolicy.ts
62 lines (49 loc) · 1.75 KB
/
BitmovinYospacePlayerPolicy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { LinearAd } from 'bitmovin-player';
import { BitmovinYospacePlayerAPI, BitmovinYospacePlayerPolicy, YospaceAdBreak } from './BitmovinYospacePlayerAPI';
export class DefaultBitmovinYospacePlayerPolicy implements BitmovinYospacePlayerPolicy {
private player: BitmovinYospacePlayerAPI;
constructor(player: BitmovinYospacePlayerAPI) {
this.player = player;
}
canSeek(): boolean {
// allow only seeking if no ad is playing
return !this.player.ads.getActiveAd();
}
canSeekTo(seekTarget: number): number {
const currentTime = this.player.getCurrentTime();
// @ts-expect-error the BitmovinYospacePlayerAPI interface is not up to date
const adBreaks: YospaceAdBreak[] = this.player.ads.list();
const skippedAdBreaks = adBreaks.filter((adBreak) => {
return adBreak.active && adBreak.scheduleTime > currentTime && adBreak.scheduleTime < seekTarget;
});
if (skippedAdBreaks.length > 0 && !this.player.isAdImmunityActive()) {
const adBreakToPlay = skippedAdBreaks[skippedAdBreaks.length - 1];
return adBreakToPlay.scheduleTime;
}
return seekTarget;
}
canSkip(): number {
const currentAd = this.player.ads.getActiveAd();
if (currentAd && currentAd.isLinear && !this.player.isLive()) {
const currentTime = this.player.getCurrentTime();
if ((currentAd as LinearAd).skippableAfter < 0) {
return -1;
}
if (currentTime >= (currentAd as LinearAd).skippableAfter) {
return 0;
} else {
return (currentAd as LinearAd).skippableAfter - currentTime;
}
}
return -1;
}
canMute(): boolean {
return true;
}
canPause(): boolean {
return true;
}
canChangePlaybackSpeed(): boolean {
return !this.player.ads.getActiveAd();
}
}