Skip to content

Commit

Permalink
chore: remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark committed Mar 21, 2024
1 parent ddbb29a commit 2de540a
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/ts/InternalBitmovinYospacePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,19 @@ export class InternalBitmovinYospacePlayer implements BitmovinYospacePlayerAPI {
}
};

private performBreakSkip(seekTarget: number) {
this.suppressedEventsController.add(
this.player.exports.PlayerEvent.Paused,
this.player.exports.PlayerEvent.Seek,
this.player.exports.PlayerEvent.Seeked
);

this.player.pause();
this.unpauseAfterSeek = true;

this.player.seek(seekTarget);
}

private onTimeChanged = (event: TimeChangedEvent) => {
// the offset is an attempt to prevent the first few frames of an ad
// playing before the seek past the break has time to propagate
Expand All @@ -1241,17 +1254,9 @@ export class InternalBitmovinYospacePlayer implements BitmovinYospacePlayerAPI {
if (upcomingAdBreak?.getPosition() !== 'postroll' && upcomingAdBreak?.getPosition() !== 'unknown') {
// Seek past previously deactivated ad breaks
if (upcomingAdBreak && !upcomingAdBreak.isActive()) {
this.suppressedEventsController.add(
this.player.exports.PlayerEvent.Paused,
this.player.exports.PlayerEvent.Seek,
this.player.exports.PlayerEvent.Seeked
);

this.player.pause();
this.unpauseAfterSeek = true;

Logger.log('[BitmovinYospacePlayer] - Ad Immunity pausing and seeking past deactivated ad break');
this.player.seek(toSeconds(upcomingAdBreak.getStart() + upcomingAdBreak.getDuration()));

this.performBreakSkip(toSeconds(upcomingAdBreak.getStart() + upcomingAdBreak.getDuration()));

// do not propagate time to the rest of the app, we want to seek past it
return;
Expand All @@ -1261,17 +1266,9 @@ export class InternalBitmovinYospacePlayer implements BitmovinYospacePlayerAPI {
if (upcomingAdBreak && this.adImmune) {
upcomingAdBreak.setInactive();

this.suppressedEventsController.add(
this.player.exports.PlayerEvent.Paused,
this.player.exports.PlayerEvent.Seek,
this.player.exports.PlayerEvent.Seeked
);

this.player.pause();
this.unpauseAfterSeek = true;

Logger.log('[BitmovinYospacePlayer] - Ad Immunity pausing, seeking past and deactivating ad break');
this.player.seek(toSeconds(upcomingAdBreak.getStart() + upcomingAdBreak.getDuration()));

this.performBreakSkip(toSeconds(upcomingAdBreak.getStart() + upcomingAdBreak.getDuration()));

// do not propagate time to the rest of the app, we want to seek past it
return;
Expand Down

0 comments on commit 2de540a

Please sign in to comment.