| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { PlaybackStateBridge } from './PlaybackStateBridge'
- import { VideoItem } from '../viewmodel/VideoItem'
- export interface PlaybackRuntime {
- playQueue: (queue: VideoItem[], startIndex: number, source: string) => Promise<void>
- playOrPause: () => Promise<void>
- playNext: () => Promise<void>
- playPrevious: () => Promise<void>
- seekTo: (value: string, source?: string) => Promise<void>
- }
- export class PlaybackCoordinator {
- private static instance?: PlaybackCoordinator
- private runtime?: PlaybackRuntime
- private stateBridge: PlaybackStateBridge = PlaybackStateBridge.getInstance()
- public static getInstance(): PlaybackCoordinator {
- if (!PlaybackCoordinator.instance) {
- PlaybackCoordinator.instance = new PlaybackCoordinator()
- }
- return PlaybackCoordinator.instance
- }
- public setRuntime(runtime: PlaybackRuntime): void {
- this.runtime = runtime
- }
- public clearRuntime(runtime?: PlaybackRuntime): void {
- if (!runtime || this.runtime === runtime) {
- this.runtime = undefined
- }
- }
- public async playQueue(queue: VideoItem[], startIndex: number, source: string): Promise<void> {
- if (!this.runtime || queue.length <= 0) {
- return
- }
- this.stateBridge.replaceQueue(queue, startIndex)
- await this.runtime.playQueue(queue, this.stateBridge.getSnapshot().currentIndex, source)
- }
- public async playSong(song: VideoItem, source: string): Promise<void> {
- await this.playQueue([song], 0, source)
- }
- public async playOrPause(): Promise<void> {
- await this.runtime?.playOrPause()
- }
- public async playNext(): Promise<void> {
- await this.runtime?.playNext()
- }
- public async playPrevious(): Promise<void> {
- await this.runtime?.playPrevious()
- }
- public async seekTo(value: string, source?: string): Promise<void> {
- await this.runtime?.seekTo(value, source)
- }
- }
|