fix: Increase reliability of media auto actions (e.g. play) (#1934)

Refactors media player handling entirely to make the code more
consistent and less boilerplate. Add testing for media player actions.

- Closes #1921
- Closes #1916
This commit is contained in:
Dermot Duffy
2025-03-03 20:59:01 -08:00
committed by GitHub
parent d4650eae8a
commit 3b77b11196
58 changed files with 1972 additions and 1165 deletions
+1 -1
View File
@@ -4,6 +4,6 @@ import { AdvancedCameraCardAction } from './base';
export class MuteAction extends AdvancedCameraCardAction<GeneralActionConfig> {
public async execute(api: CardActionsAPI): Promise<void> {
await api.getMediaLoadedInfoManager().get()?.player?.mute();
await api.getMediaLoadedInfoManager().get()?.mediaPlayerController?.mute();
}
}
+1 -1
View File
@@ -4,6 +4,6 @@ import { AdvancedCameraCardAction } from './base';
export class PauseAction extends AdvancedCameraCardAction<GeneralActionConfig> {
public async execute(api: CardActionsAPI): Promise<void> {
await api.getMediaLoadedInfoManager().get()?.player?.pause();
await api.getMediaLoadedInfoManager().get()?.mediaPlayerController?.pause();
}
}
+1 -1
View File
@@ -4,6 +4,6 @@ import { AdvancedCameraCardAction } from './base';
export class PlayAction extends AdvancedCameraCardAction<GeneralActionConfig> {
public async execute(api: CardActionsAPI): Promise<void> {
await api.getMediaLoadedInfoManager().get()?.player?.play();
await api.getMediaLoadedInfoManager().get()?.mediaPlayerController?.play();
}
}
@@ -4,6 +4,6 @@ import { AdvancedCameraCardAction } from './base';
export class UnmuteAction extends AdvancedCameraCardAction<GeneralActionConfig> {
public async execute(api: CardActionsAPI): Promise<void> {
await api.getMediaLoadedInfoManager().get()?.player?.unmute();
await api.getMediaLoadedInfoManager().get()?.mediaPlayerController?.unmute();
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ export class DownloadManager {
const url = await this._api
.getMediaLoadedInfoManager()
.get()
?.player?.getScreenshotURL();
?.mediaPlayerController?.getScreenshotURL();
if (url) {
downloadURL(url, generateScreenshotTitle(this._api.getViewManager().getView()));
}
@@ -27,14 +27,16 @@ export class WebkitFullScreenProvider
protected _stateChangeHandler = (change: ConditionStateChange): void => {
if (
change.old.mediaLoadedInfo?.player?.getFullscreenElement() !==
change.new.mediaLoadedInfo?.player?.getFullscreenElement()
change.old.mediaLoadedInfo?.mediaPlayerController?.getFullscreenElement() !==
change.new.mediaLoadedInfo?.mediaPlayerController?.getFullscreenElement()
) {
const oldElement = change.old.mediaLoadedInfo?.player?.getFullscreenElement();
const oldElement =
change.old.mediaLoadedInfo?.mediaPlayerController?.getFullscreenElement();
oldElement?.removeEventListener('webkitbeginfullscreen', this._handler);
oldElement?.removeEventListener('webkitendfullscreen', this._endHandler);
const newElement = change.new.mediaLoadedInfo?.player?.getFullscreenElement();
const newElement =
change.new.mediaLoadedInfo?.mediaPlayerController?.getFullscreenElement();
newElement?.addEventListener('webkitbeginfullscreen', this._handler);
newElement?.addEventListener('webkitendfullscreen', this._endHandler);
}
@@ -46,7 +48,7 @@ export class WebkitFullScreenProvider
const element = this._api
.getMediaLoadedInfoManager()
.get()
?.player?.getFullscreenElement();
?.mediaPlayerController?.getFullscreenElement();
return element instanceof HTMLVideoElement ? element : null;
}