Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to play a video chunk as soon as a response is received? #6560

Closed
brodiddev opened this issue May 8, 2024 · 2 comments
Closed
Labels
type: question A question from the community

Comments

@brodiddev
Copy link

brodiddev commented May 8, 2024

Have you read the Tutorials?
yes

Have you read the FAQ and checked for duplicate open issues?
yes

If the question is related to FairPlay, have you read the tutorial?

What version of Shaka Player are you using?
4.9.11

What browser and OS are you using?
Window Chrome

Please ask your question
I am using the live stream below.
After meeting the 4-second buffer, playback is starting at a point where the remaining buffer is 3 seconds.
But it always starts playing from the 6th video chunk.
This appears to play the last 6th video chunk of the last downloaded playlist.

Is it possible to play directly from the 3rd video chunk?

await player.load(url);
this.videoElement.pause(); 
await this.ensurePlaybackBuffer(4);
this.videoElement.play();
async ensurePlaybackBuffer(minBufferLength) {
return new Promise((resolve) => {
	const checkBuffer = () => {
		const buffered = this.videoElement.buffered;
		if (buffered.length > 0) {
			const bufferEnd = buffered.end(buffered.length - 1);
			const currentTime = this.videoElement.currentTime;
			const bufferedAmount = bufferEnd - currentTime;

			if (bufferedAmount >= minBufferLength) {
				const targetTime = currentTime + 3;
				if (bufferEnd > targetTime) {
					this.videoElement.currentTime = targetTime;
				} else {
				}
				resolve();
			} else {
				setTimeout(checkBuffer, 100);
			}
		} else {
			setTimeout(checkBuffer, 100);
		}
	};
	checkBuffer();
});
}
export function getDefaultConfig() {
	return {
		abr: { enabled: false },
		streaming: {
			bufferingGoal: 30,
			rebufferingGoal: 5,
			lowLatencyMode: true,
			startAtSegmentBoundary: true,
			liveSyncMaxLatency: 2,
			updateIntervalSeconds: 0.5,
			retryParameters: { baseDelay: 1000, timeout: 5000, maxAttempts: 2 },
		},
		manifest: {
			hls: {
				liveSegmentsDelay: 1,
			},
			retryParameters: { baseDelay: 1000, timeout: 5000, maxAttempts: 2 },
		},
	};
}
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:11121
#EXT-X-MAP:URI="https://test.com/beta-media/video/1920x1080/surplus.m4s"
#EXT-X-PROGRAM-DATE-TIME:2024-05-08T13:26:42.537Z
#EXTINF:1,
https://test.com/beta-media/video/1920x1080/11121.mp4v
#EXT-X-PROGRAM-DATE-TIME:2024-05-08T13:26:43.537Z
#EXTINF:1,
https://test.com/beta-media/video/1920x1080/11122.mp4v
#EXT-X-PROGRAM-DATE-TIME:2024-05-08T13:26:44.537Z
#EXTINF:1,
https://test.com/beta-media/video/1920x1080/11123.mp4v
#EXT-X-PROGRAM-DATE-TIME:2024-05-08T13:26:45.537Z
#EXTINF:1,
https://test.com/beta-media/video/1920x1080/11124.mp4v
#EXT-X-PROGRAM-DATE-TIME:2024-05-08T13:26:46.537Z
#EXTINF:1,
https://testcom/beta-media/video/1920x1080/11125.mp4v
#EXT-X-PROGRAM-DATE-TIME:2024-05-08T13:26:47.537Z
#EXTINF:1,
https://test.com/beta-media/video/1920x1080/11126.mp4v
@brodiddev brodiddev added the type: question A question from the community label May 8, 2024
@joeyparrish
Copy link
Member

I am using the live stream below. After meeting the 4-second buffer, playback is starting at a point where the remaining buffer is 3 seconds. But it always starts playing from the 6th video chunk. This appears to play the last 6th video chunk of the last downloaded playlist.

Is it possible to play directly from the 3rd video chunk?

The default for HLS is follow the guidance in the HLS spec, and to join live streams 3 segments back from the live edge.

You can configure this threshold with something like

// Segments from the live edge, specific to HLS:
player.configure('manifest.hls.liveSegmentsDelay', 6 /* segments */);

or

// Seconds from the live edge, generic, defaults to 0 meaning a different behavior
// for DASH & HLS.
player.configure('manifest.defaultPresentationDelay, 6 /* seconds */);
// The DASH default is to use MPD's suggestedPresentationDelay,
// falling back to 1.5 * minBufferTime if missing.
// The HLS default is to use segment delay, defaulting to 3 above.

See also:

@brodiddev
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question A question from the community
Projects
None yet
Development

No branches or pull requests

2 participants