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

fix (SUP-46985): Replay button unresponsive when PiP is activated #809

Merged
merged 5 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/engines/html5/html5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CapabilityResult, ICapability } from '../../types';
import { PKABRRestrictionObject, PKDrmConfigObject, PKDrmDataObject, PKMediaSourceObject, PKVideoElementStore } from '../../types';
import { IEngine } from '../../types';
import Track from '../../track/track';
import Env from '../../../src/utils/env';

const SHORT_BUFFERING_TIMEOUT: number = 200;

Expand Down Expand Up @@ -513,12 +514,32 @@ export default class Html5 extends FakeEventTarget implements IEngine {
return this._mediaSourceAdapter ? this._mediaSourceAdapter.isLive() : false;
}

/**
* Checks if the video playback has ended and resets it if necessary.
* Specifically handles Safari in Picture-in-Picture mode for non-live streams.
*
* @private
* @returns {void}
*/
private resetIfPlaybackEnded(): void {
const currentTimeMs = Math.round(this._el.currentTime * 1000);
const durationMs = Math.round(this._el.duration * 1000);

if (currentTimeMs >= durationMs || this._el.ended) {
this._el.currentTime = 0;
}
}

/**
* Start/resume playback.
* @public
* @returns {?Promise<*>} - play promise
*/
public play(): Promise<void> {
if (Env.isSafari && this.isInPictureInPicture && !this.isLive()) {
this.resetIfPlaybackEnded();
}

const playPromise = this._el.play();
if (playPromise) {
playPromise.catch((err) => this.dispatchEvent(new FakeEvent(CustomEventType.PLAY_FAILED, { error: err })));
Expand Down