Skip to content

Commit

Permalink
fix pausing of player popup
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Dec 20, 2024
1 parent 9e0675a commit 8be5cd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/MediaWidget/VideoJSComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let options: VideoJsPlayerOptions = {
youtube: { ytControls: 0, rel: 0 },
};

enum PLAYER_STATE {
export enum PLAYER_STATE {
INITIALIZING,
PLAYING,
PAUSED,
Expand Down
11 changes: 11 additions & 0 deletions src/components/PlayerPopup/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PlayerAdapterEvent,
createPlayerAdapter,
} from "./PlayerAdapter";
import { PLAYER_STATE } from "../MediaWidget/VideoJSComponent";

export interface AbstractPlayerStore {
play(song?: Song): void;
Expand All @@ -19,6 +20,7 @@ export interface PlayerConfiguration {

export class PlayerStore implements AbstractPlayerStore {
player: PlayerAdapter | null = null;
state: PLAYER_STATE = PLAYER_STATE.INITIALIZING;
song: Song | null = null;
widgetId: string;
conf: PlayerConfiguration;
Expand Down Expand Up @@ -65,6 +67,13 @@ export class PlayerStore implements AbstractPlayerStore {
"create with volume",
);
this.player?.volume(this._volume);
this.player?.on(PlayerAdapterEvent.PLAY, () => {
if (PLAYER_STATE.SHOULD_BE_STOPED === this.state){
this.player?.pause();
return;
}
this.state = PLAYER_STATE.PLAYING;
})
this.player?.on(PlayerAdapterEvent.ENDED, () => {
log.debug(`finished playing song`);
publish(this.conf.remoteplayerfeedback, {
Expand Down Expand Up @@ -93,9 +102,11 @@ export class PlayerStore implements AbstractPlayerStore {
this.player = null;
}
if (json.command === "pause") {
this.state = PLAYER_STATE.SHOULD_BE_STOPED;
this.player?.pause();
}
if (json.command === "resume") {
this.state = PLAYER_STATE.PLAYING;
this.player?.play();
}
if (json.command === "volume") {
Expand Down
1 change: 0 additions & 1 deletion src/components/PlayerPopup/PlayerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const PlayerPopup = observer(({ player }: { player: AbstractPlayerStore }) => {
<div id="mediaplayer" className="full-height vjs-big-play-centered" />
</>
);

});

export default PlayerPopup;

0 comments on commit 8be5cd5

Please sign in to comment.