2023-07-23 16:30:22 +02:00
|
|
|
import { MakeSlice } from "@/stores/player/slices/types";
|
|
|
|
|
|
|
|
export interface PlayingSlice {
|
|
|
|
mediaPlaying: {
|
|
|
|
isPlaying: boolean;
|
|
|
|
isPaused: boolean;
|
|
|
|
isSeeking: boolean; // seeking with progress bar
|
|
|
|
isDragSeeking: boolean; // is seeking for our custom progress bar
|
|
|
|
isLoading: boolean; // buffering or not
|
|
|
|
hasPlayedOnce: boolean; // has the video played at all?
|
|
|
|
volume: number;
|
2023-10-19 19:27:21 +02:00
|
|
|
playbackRate: number;
|
2023-07-23 16:30:22 +02:00
|
|
|
};
|
|
|
|
play(): void;
|
|
|
|
pause(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createPlayingSlice: MakeSlice<PlayingSlice> = (set) => ({
|
|
|
|
mediaPlaying: {
|
|
|
|
isPlaying: false,
|
|
|
|
isPaused: true,
|
|
|
|
isLoading: false,
|
|
|
|
isSeeking: false,
|
|
|
|
isDragSeeking: false,
|
|
|
|
hasPlayedOnce: false,
|
2023-10-11 22:09:28 +02:00
|
|
|
volume: 1,
|
2023-10-19 19:27:21 +02:00
|
|
|
playbackRate: 1,
|
2023-07-23 16:30:22 +02:00
|
|
|
},
|
|
|
|
play() {
|
|
|
|
set((state) => {
|
|
|
|
state.mediaPlaying.isPlaying = true;
|
|
|
|
state.mediaPlaying.isPaused = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
pause() {
|
|
|
|
set((state) => {
|
|
|
|
state.mediaPlaying.isPlaying = false;
|
|
|
|
state.mediaPlaying.isPaused = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|