mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Receivers: Resume on receiver timestamp on sender reconnect
This commit is contained in:
parent
2afa866d82
commit
a5fc61fd85
2 changed files with 19 additions and 27 deletions
|
@ -8,13 +8,15 @@ export enum PlayerType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
private player: dashjs.MediaPlayerClass | HTMLVideoElement
|
private player: dashjs.MediaPlayerClass | HTMLVideoElement;
|
||||||
private hlsPlayer: Hls | undefined
|
private hlsPlayer: Hls | undefined;
|
||||||
public playerType: PlayerType
|
private source: string;
|
||||||
|
public playerType: PlayerType;
|
||||||
|
|
||||||
constructor(playerType: PlayerType, player: dashjs.MediaPlayerClass | HTMLVideoElement, hlsPlayer?: Hls) {
|
constructor(playerType: PlayerType, player: dashjs.MediaPlayerClass | HTMLVideoElement, source: string, hlsPlayer?: Hls) {
|
||||||
this.playerType = playerType;
|
this.playerType = playerType;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.source = source;
|
||||||
this.hlsPlayer = playerType === PlayerType.Hls ? hlsPlayer : null;
|
this.hlsPlayer = playerType === PlayerType.Hls ? hlsPlayer : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,12 +164,7 @@ export class Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSource(): string {
|
getSource(): string {
|
||||||
if (this.playerType === PlayerType.Dash) {
|
return this.source;
|
||||||
const videoPlayer = this.player as dashjs.MediaPlayerClass;
|
|
||||||
return videoPlayer.getSource() instanceof String ? videoPlayer.getSource() as string : JSON.stringify(videoPlayer.getSource());
|
|
||||||
} else { // HLS, HTML
|
|
||||||
return (this.player as HTMLVideoElement).src;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getBufferLength(): number {
|
getBufferLength(): number {
|
||||||
|
|
|
@ -122,22 +122,10 @@ function onPlay(_event, value: PlayMessage) {
|
||||||
const currentVolume = player ? player.getVolume() : null;
|
const currentVolume = player ? player.getVolume() : null;
|
||||||
const currentPlaybackRate = player ? player.getPlaybackRate() : null;
|
const currentPlaybackRate = player ? player.getPlaybackRate() : null;
|
||||||
|
|
||||||
playerPrevTime = 0;
|
|
||||||
lastPlayerUpdateGenerationTime = 0;
|
|
||||||
isLive = false;
|
|
||||||
isLivePosition = false;
|
|
||||||
captionsBaseHeight = captionsBaseHeightExpanded;
|
|
||||||
|
|
||||||
if (player) {
|
if (player) {
|
||||||
if (player.getSource() === value.url) {
|
if ((player.getSource() === value.url) || (player.getSource() === value.content)) {
|
||||||
if (value.time) {
|
if (value.time) {
|
||||||
if (Math.abs(value.time - player.getCurrentTime()) < 5000) {
|
console.info('Skipped changing video URL because URL is the same. Discarding time and using current receiver time instead');
|
||||||
console.warn(`Skipped changing video URL because URL and time is (nearly) unchanged: ${value.url}, ${player.getSource()}, ${formatDuration(value.time)}, ${formatDuration(player.getCurrentTime())}`);
|
|
||||||
} else {
|
|
||||||
console.info(`Skipped changing video URL because URL is the same, but time was changed, seeking instead: ${value.url}, ${player.getSource()}, ${formatDuration(value.time)}, ${formatDuration(player.getCurrentTime())}`);
|
|
||||||
|
|
||||||
player.setCurrentTime(value.time);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -145,11 +133,18 @@ function onPlay(_event, value: PlayMessage) {
|
||||||
player.destroy();
|
player.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerPrevTime = 0;
|
||||||
|
lastPlayerUpdateGenerationTime = 0;
|
||||||
|
isLive = false;
|
||||||
|
isLivePosition = false;
|
||||||
|
captionsBaseHeight = captionsBaseHeightExpanded;
|
||||||
|
|
||||||
if ((value.url || value.content) && value.container && videoElement) {
|
if ((value.url || value.content) && value.container && videoElement) {
|
||||||
if (value.container === 'application/dash+xml') {
|
if (value.container === 'application/dash+xml') {
|
||||||
console.log("Loading dash player");
|
console.log("Loading dash player");
|
||||||
const dashPlayer = dashjs.MediaPlayer().create();
|
const dashPlayer = dashjs.MediaPlayer().create();
|
||||||
player = new Player(PlayerType.Dash, dashPlayer);
|
const source = value.content ? value.content : value.url;
|
||||||
|
player = new Player(PlayerType.Dash, dashPlayer, source);
|
||||||
|
|
||||||
dashPlayer.extend("RequestModifier", () => {
|
dashPlayer.extend("RequestModifier", () => {
|
||||||
return {
|
return {
|
||||||
|
@ -272,7 +267,7 @@ function onPlay(_event, value: PlayMessage) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
player = new Player(PlayerType.Hls, videoElement, hlsPlayer);
|
player = new Player(PlayerType.Hls, videoElement, value.url, hlsPlayer);
|
||||||
|
|
||||||
// value.url = "https://devstreaming-cdn.apple.com/videos/streaming/examples/adv_dv_atmos/main.m3u8?ref=developerinsider.co";
|
// value.url = "https://devstreaming-cdn.apple.com/videos/streaming/examples/adv_dv_atmos/main.m3u8?ref=developerinsider.co";
|
||||||
hlsPlayer.loadSource(value.url);
|
hlsPlayer.loadSource(value.url);
|
||||||
|
@ -281,7 +276,7 @@ function onPlay(_event, value: PlayMessage) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("Loading html player");
|
console.log("Loading html player");
|
||||||
player = new Player(PlayerType.Html, videoElement);
|
player = new Player(PlayerType.Html, videoElement, value.url);
|
||||||
|
|
||||||
videoElement.src = value.url;
|
videoElement.src = value.url;
|
||||||
videoElement.load();
|
videoElement.load();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue