Skip to content

Commit

Permalink
feat(player): add new artwork player prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Mar 18, 2024
1 parent e36958c commit c0a4eaf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/vidstack/src/core/api/player-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { MediaLoadingStrategy, MediaPosterLoadingStrategy } from './types';

export const mediaPlayerProps: MediaPlayerProps = {
artist: '',
artwork: null,
autoplay: false,
autoPlay: false,
clipStartTime: 0,
Expand Down Expand Up @@ -60,6 +61,7 @@ export interface MediaPlayerProps
extends Pick<
Writable<MediaState>,
| 'artist'
| 'artwork'
| 'autoPlay'
| 'clipStartTime'
| 'clipEndTime'
Expand Down
5 changes: 5 additions & 0 deletions packages/vidstack/src/core/api/player-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface MediaPlayerState extends MediaState {}

export const mediaState = new State<MediaState>({
artist: '',
artwork: null,
audioTrack: null,
audioTracks: [],
autoPlay: false,
Expand Down Expand Up @@ -748,6 +749,10 @@ export interface MediaState {
* layout and it will be included in the Media Session API.
*/
artist: string;
/**
* Images to be included in the Media Session API.
*/
artwork: MediaImage[] | null;
/**
* The list of all available text tracks.
*/
Expand Down
7 changes: 4 additions & 3 deletions packages/vidstack/src/core/state/media-state-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MediaStateSync extends MediaPlayerController {
if (__SERVER__) return;

if (__DEV__) effect(this._watchLogLevel.bind(this));
effect(this._watchArtist.bind(this));
effect(this._watchMetadata.bind(this));
effect(this._watchAutoplay.bind(this));
effect(this._watchClipTimes.bind(this));
effect(this._watchControls.bind(this));
Expand Down Expand Up @@ -71,9 +71,10 @@ export class MediaStateSync extends MediaPlayerController {
this.$state.logLevel.set(this.$props.logLevel());
}

private _watchArtist() {
const { artist } = this.$props;
private _watchMetadata() {
const { artist, artwork } = this.$props;
this.$state.artist.set(artist());
this.$state.artwork.set(artwork());
}

private _watchTitle() {
Expand Down
4 changes: 2 additions & 2 deletions packages/vidstack/src/core/state/navigator-media-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class NavigatorMediaSession extends MediaPlayerController {
}

protected _onMetadataChange() {
const { title, artist, poster } = this.$state;
const { title, artist, artwork, poster } = this.$state;
navigator.mediaSession.metadata = new MediaMetadata({
title: title(),
artist: artist(),
artwork: [{ src: poster() }],
artwork: artwork() ?? [{ src: poster() }],
});
}

Expand Down

0 comments on commit c0a4eaf

Please sign in to comment.