Skip to content

Commit

Permalink
Offset the playback position from stream start for Yospace DVRLive se…
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-sandell and MattiasBuelens authored May 27, 2024
1 parent 0cb0463 commit b65601c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-crabs-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@theoplayer/yospace-connector-web": patch
---

Fixed playback position reporting for live DVR streams (with `streamType` set to `"livepause"`).
32 changes: 29 additions & 3 deletions yospace/src/integration/YospaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { isYospaceTypedSource, yoSpaceWebSdkIsAvailable } from '../utils/Yospace
import { PromiseController } from '../utils/PromiseController';
import { PlayerEvent } from '../yospace/PlayerEvent';
import { toSources } from '../utils/SourceUtils';
import { ResultCode, SessionState, YospaceSessionManager } from '../yospace/YospaceSessionManager';
import {
PlaybackMode,
ResultCode,
SessionState,
YospaceSession,
YospaceSessionDVRLive,
YospaceSessionManager
} from '../yospace/YospaceSessionManager';
import { YospaceWindow } from '../yospace/YospaceWindow';
import { YospaceAdHandler } from './YospaceAdHandler';
import { YospaceUiHandler } from './YospaceUIHandler';
Expand Down Expand Up @@ -123,8 +130,23 @@ export class YospaceManager extends DefaultEventDispatcher<YospaceEventMap> {
}

private updateYospaceWithPlaybackPosition = () => {
const currentTime = this.player.currentTime * 1000;
this.sessionManager?.onPlayheadUpdate(currentTime);
const session = this.sessionManager;
if (!session) {
return;
}

let currentTime = this.player.currentTime * 1000;

// For Yospace DVRLive sessions we need to offset the playback position from the stream start time
if (isSessionDVRLive(session)) {
const ast = session.getManifestData<Date>('availabilityStartTime')?.getTime();
const sst = session.getStreamStart();
// availabilityStartTime is initially undefined, and streamStart is initially -1
const delta = (sst < 0 ? 0 : sst) - (ast || 0);
currentTime = Math.round(currentTime - delta);
}

session.onPlayheadUpdate(currentTime);
};

private onInitComplete = (e: any) => {
Expand Down Expand Up @@ -253,3 +275,7 @@ export class YospaceManager extends DefaultEventDispatcher<YospaceEventMap> {
this.didFirstPlay = false;
}
}

function isSessionDVRLive(session: YospaceSession): session is YospaceSessionDVRLive {
return session.getPlaybackMode() === PlaybackMode.DVRLIVE;
}
31 changes: 30 additions & 1 deletion yospace/src/yospace/YospaceSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ export enum SessionState {
SHUT_DOWN
}

export enum PlaybackMode {
LIVE = 0,
DVRLIVE = 1,
VOD = 2
}

export type YospaceSessionCallback = (state: SessionState, result: ResultCode) => void;
export type YospaceSessionManagerCreator = {
create(url: string, properties: object, successCallback: YospaceSessionCallback): void;
};

export interface YospaceSessionManager {
export interface YospaceSession {
getPlaybackMode(): PlaybackMode;

getPlaybackUrl(): string;

getResultCode(): number;
Expand All @@ -41,3 +49,24 @@ export interface YospaceSessionManager {

shutdown(): void;
}

export interface YospaceSessionDVRLive extends YospaceSession {
getPlaybackMode(): PlaybackMode.DVRLIVE;

getDuration(): number;

getStreamStart(): number;

getManifestData<T>(key: string): T | undefined;
getManifestData(): Map<string, any>;

getWindowStart(): number;

getWindowEnd(): number;

getWindowSize(): number;

setAdBreaksInactivePriorTo(playhead: number): void;
}

export { YospaceSession as YospaceSessionManager };

0 comments on commit b65601c

Please sign in to comment.