@ldelia/react-media 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/reproduction-widget/models/Player/PlayAlongPlayer.d.ts +3 -2
- package/dist/components/reproduction-widget/models/Player/PlayAlongPlayer.js +4 -2
- package/dist/components/reproduction-widget/models/Player/YouTubePlayer.d.ts +1 -2
- package/dist/components/reproduction-widget/models/Player/YouTubePlayer.js +3 -25
- package/dist/components/reproduction-widget/models/Reproduction.js +0 -2
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="youtube" />
|
|
2
|
+
import PlayerState = YT.PlayerState;
|
|
1
3
|
declare const dispatchOnReadyHandlers: unique symbol;
|
|
2
4
|
declare const dispatchOnFinishHandlers: unique symbol;
|
|
3
5
|
export declare class PlayAlongPlayer {
|
|
@@ -21,13 +23,12 @@ export declare class PlayAlongPlayer {
|
|
|
21
23
|
seekTo(seconds: number): void;
|
|
22
24
|
getCurrentTime(): number;
|
|
23
25
|
getDuration(): number;
|
|
26
|
+
getState(): PlayerState.PLAYING | PlayerState.PAUSED;
|
|
24
27
|
isAvailable(): boolean;
|
|
25
28
|
getAvailablePlaybackRates(): number[];
|
|
26
29
|
setPlaybackRate(playbackRate: number): void;
|
|
27
30
|
on(eventName: keyof typeof PlayAlongPlayer.EVENTS, handler: () => void): number | undefined;
|
|
28
31
|
dispatch(eventName: keyof typeof PlayAlongPlayer.EVENTS): void;
|
|
29
|
-
countingStarted(): void;
|
|
30
|
-
countingFinished(): void;
|
|
31
32
|
setVolume(volume: number): void;
|
|
32
33
|
getVolume(): number;
|
|
33
34
|
private setInnerPlayer;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PLAYER_EVENTS } from './PlayerEvents';
|
|
2
|
+
var PlayerState = YT.PlayerState;
|
|
2
3
|
const dispatchOnReadyHandlers = Symbol();
|
|
3
4
|
const dispatchOnFinishHandlers = Symbol();
|
|
4
5
|
export class PlayAlongPlayer {
|
|
@@ -50,6 +51,9 @@ export class PlayAlongPlayer {
|
|
|
50
51
|
getDuration() {
|
|
51
52
|
return this.duration;
|
|
52
53
|
}
|
|
54
|
+
getState() {
|
|
55
|
+
return this.isRunning ? PlayerState.PLAYING : PlayerState.PAUSED;
|
|
56
|
+
}
|
|
53
57
|
isAvailable() {
|
|
54
58
|
return true;
|
|
55
59
|
}
|
|
@@ -85,8 +89,6 @@ export class PlayAlongPlayer {
|
|
|
85
89
|
handler();
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
|
-
countingStarted() { }
|
|
89
|
-
countingFinished() { }
|
|
90
92
|
setVolume(volume) { }
|
|
91
93
|
getVolume() { return 0; }
|
|
92
94
|
setInnerPlayer(innerPlayer) {
|
|
@@ -28,12 +28,11 @@ export declare class YouTubePlayer {
|
|
|
28
28
|
getCurrentTime(): number;
|
|
29
29
|
getDuration(): number | undefined;
|
|
30
30
|
getAvailablePlaybackRates(): number[];
|
|
31
|
+
getState(): YT.PlayerState;
|
|
31
32
|
setPlaybackRate(playbackRate: number): void;
|
|
32
33
|
isAvailable(): boolean;
|
|
33
34
|
on(eventName: keyof typeof PlayAlongPlayer.EVENTS, handler: (error?: any) => void): number | undefined;
|
|
34
35
|
dispatch(eventName: keyof typeof PlayAlongPlayer.EVENTS, error?: any): void;
|
|
35
|
-
countingStarted(): void;
|
|
36
|
-
countingFinished(): void;
|
|
37
36
|
private getErrorMessage;
|
|
38
37
|
}
|
|
39
38
|
export {};
|
|
@@ -89,6 +89,9 @@ export class YouTubePlayer {
|
|
|
89
89
|
getAvailablePlaybackRates() {
|
|
90
90
|
return this.getInnerPlayer().getAvailablePlaybackRates();
|
|
91
91
|
}
|
|
92
|
+
getState() {
|
|
93
|
+
return this.getInnerPlayer().getPlayerState();
|
|
94
|
+
}
|
|
92
95
|
setPlaybackRate(playbackRate) {
|
|
93
96
|
if (!this.getAvailablePlaybackRates().includes(playbackRate)) {
|
|
94
97
|
throw new Error(`The PlayAlongPlayer doesn't support a playbackRate with value ${playbackRate}`);
|
|
@@ -128,31 +131,6 @@ export class YouTubePlayer {
|
|
|
128
131
|
setTimeout(() => handler(error), 0);
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
countingStarted() {
|
|
132
|
-
/**
|
|
133
|
-
* iOS browsers enforce strict autoplay policies that require video playback
|
|
134
|
-
* to begin synchronously within a user interaction event (e.g., a tap or click).
|
|
135
|
-
* When we implemented the counting-in feature (1, 2, 1, 2, 3, go...),
|
|
136
|
-
* the asynchronous delays between counts caused iOS to lose the user interaction context,
|
|
137
|
-
* blocking video playback after the countdown completed.
|
|
138
|
-
* The video would work fine on web and Android, but fail to start on iOS Safari.
|
|
139
|
-
* To resolve this, we adopted a muted-first approach:
|
|
140
|
-
* the video begins playing immediately when the user initiates playback,
|
|
141
|
-
* but remains muted during the countdown sequence.
|
|
142
|
-
* Once the countdown completes, we unmute the video and restore the desired volume.
|
|
143
|
-
* This strategy satisfies iOS's autoplay requirements (muted videos can autoplay)
|
|
144
|
-
* while preserving the musical countdown experience.
|
|
145
|
-
* The user never notices the video is playing during the countdown
|
|
146
|
-
* since it's both muted and visually obscured by the countdown overlay.
|
|
147
|
-
* */
|
|
148
|
-
this.getInnerPlayer().setVolume(0);
|
|
149
|
-
this.getInnerPlayer().playVideo();
|
|
150
|
-
}
|
|
151
|
-
countingFinished() {
|
|
152
|
-
this.getInnerPlayer().pauseVideo();
|
|
153
|
-
this.getInnerPlayer().seekTo(0, true);
|
|
154
|
-
this.setVolume(this.volume);
|
|
155
|
-
}
|
|
156
134
|
getErrorMessage(errorCode) {
|
|
157
135
|
switch (errorCode) {
|
|
158
136
|
case YT.PlayerError.InvalidParam:
|
|
@@ -200,7 +200,6 @@ export class Reproduction {
|
|
|
200
200
|
}
|
|
201
201
|
countInAndPlay(timeout, limit) {
|
|
202
202
|
// the initial count starts instantly, no need to wait
|
|
203
|
-
this.player.countingStarted();
|
|
204
203
|
this.countingInCounter++;
|
|
205
204
|
this.dispatch(Reproduction.EVENTS.COUNTING_IN, { countingInCounter: this.countingInCounter });
|
|
206
205
|
const interval = setInterval(() => {
|
|
@@ -212,7 +211,6 @@ export class Reproduction {
|
|
|
212
211
|
this.countInAndPlay(this.getBPMInterval(), 5);
|
|
213
212
|
}
|
|
214
213
|
else {
|
|
215
|
-
this.player.countingFinished();
|
|
216
214
|
this.play();
|
|
217
215
|
}
|
|
218
216
|
}
|