-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of media player
- Loading branch information
1 parent
2830809
commit 8e60d11
Showing
36 changed files
with
665 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/core/types/src/services/active-media-provider-cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Effect, Option } from "effect"; | ||
import type { ProviderId, ProviderMetadata } from "../model"; | ||
import type { MediaPlayer, MediaProvider } from "./media-provider"; | ||
|
||
type ProviderWithMetadata = { | ||
readonly metadata: ProviderMetadata; | ||
readonly provider: MediaProvider; | ||
readonly player: MediaPlayer; | ||
}; | ||
|
||
/** | ||
* Defines a cache of all currently active providers. | ||
*/ | ||
export type MediaProviderById = Map<ProviderId, ProviderWithMetadata>; | ||
|
||
/** | ||
* Service that allows to cache active media providers and observe changes to | ||
* them. | ||
*/ | ||
export type IActiveMediaProviderCache = { | ||
/** | ||
* Adds the given provider to the cache. If a provider with the same ID is | ||
* already present, it will be replaced. Upon being added, the service will | ||
* listen to the provider's state changes and remove it from the cache once | ||
* it becomes inactive. | ||
*/ | ||
readonly add: ( | ||
metadata: ProviderMetadata, | ||
provider: MediaProvider, | ||
player: MediaPlayer, | ||
) => Effect.Effect<void>; | ||
|
||
/** | ||
* Returns a media provider, if it is currently active, or none otherwise. | ||
*/ | ||
readonly get: (providerId: ProviderId) => Effect.Effect< | ||
Option.Option<{ | ||
provider: MediaProvider; | ||
player: MediaPlayer; | ||
}> | ||
>; | ||
}; | ||
|
||
/** | ||
* Tag to identify the ActiveMediaProviderCache service. | ||
*/ | ||
export class ActiveMediaProviderCache extends Effect.Tag( | ||
"@echo/core-types/ActiveMediaProviderCache", | ||
)<ActiveMediaProviderCache, IActiveMediaProviderCache>() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export * from "./active-media-provider-cache"; | ||
export * from "./authentication"; | ||
export * from "./broadcast-channel"; | ||
export * from "./crypto"; | ||
export * from "./database"; | ||
export * from "./library"; | ||
export * from "./metadata-provider"; | ||
export * from "./mediaProvider"; | ||
export * from "./media-player"; | ||
export * from "./media-provider"; | ||
export * from "./player"; | ||
export * from "./provider-status"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Effect, Stream } from "effect"; | ||
|
||
/** | ||
* Current state in which the media player is in. | ||
*/ | ||
export type MediaPlayerState = | ||
| { _tag: "idle" } | ||
| { _tag: "playing" } | ||
| { _tag: "paused" }; | ||
|
||
/** | ||
* Service that provides media playback capabilities and exposes the current | ||
* state of the player. | ||
*/ | ||
type IMediaPlayer<TStreamingSource> = { | ||
/** | ||
* Starts the player with the given source. | ||
*/ | ||
readonly play: (fromSource: TStreamingSource) => Effect.Effect<void>; | ||
|
||
/** | ||
* Returns a stream that emits the current player state and any subsequent | ||
* changes to it. | ||
*/ | ||
readonly observe: Effect.Effect<Stream.Stream<MediaPlayerState>>; | ||
}; | ||
|
||
/** | ||
* A media player that can play tracks that are hosted on a file-system. | ||
*/ | ||
export type IFileMediaPlayer = IMediaPlayer<URL>; | ||
|
||
/** | ||
* A media player that can play tracks that are hosted on a third-party API. | ||
*/ | ||
export type IApiMediaPlayer = IMediaPlayer<never>; | ||
|
||
/** | ||
* Tag to identify a file-based media player. | ||
*/ | ||
export class FileMediaPlayer extends Effect.Tag("@echo/core-types/Library")< | ||
FileMediaPlayer, | ||
IMediaPlayer<URL> | ||
>() {} | ||
|
||
/** | ||
* Tag to identify an API-based media player. | ||
*/ | ||
export class ApiMediaPlayer extends Effect.Tag("@echo/core-types/Library")< | ||
ApiMediaPlayer, | ||
IMediaPlayer<never> | ||
>() {} |
Oops, something went wrong.