Skip to content

Commit 902a666

Browse files
committed
fix(player): maintain volume state across provider changes
closes #1039
1 parent 955d1ec commit 902a666

5 files changed

Lines changed: 17 additions & 27 deletions

File tree

packages/vidstack/src/components/provider/provider.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ export class MediaProvider extends Component<MediaProviderProps, MediaProviderSt
103103
// The src/loader might've changed by the time we load the provider.
104104
if (peek(this.$state.loader) !== loader) return;
105105

106-
// Initialize some props.
107-
if (provider) {
108-
peek(() => {
109-
const { muted, volume, playsinline } = this._media.$state;
110-
provider.setMuted(muted());
111-
provider.setVolume(volume());
112-
provider.setPlaysinline?.(playsinline());
113-
});
114-
}
115-
116106
this._media.delegate._notify('provider-change', provider);
117107
});
118108
}

packages/vidstack/src/core/state/media-player-delegate.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ export class MediaPlayerDelegate {
6060
.dispatch();
6161
}
6262

63+
const provider = peek(this._media.$provider),
64+
{ muted, volume, playsinline } = this._media.$state;
65+
66+
if (provider) {
67+
provider.setVolume(peek(volume));
68+
provider.setMuted(peek(muted));
69+
provider.setPlaysinline?.(peek(playsinline));
70+
}
71+
6372
if ($state.canPlay() && $state.autoplay() && !$state.started()) {
6473
await this._attemptAutoplay(trigger);
6574
}

packages/vidstack/src/providers/embed/EmbedProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export abstract class EmbedProvider<Message> {
5555
}
5656

5757
protected _postMessage(message: any, target?: string) {
58+
if (__SERVER__) return;
5859
this._iframe.contentWindow?.postMessage(JSON.stringify(message), target ?? '*');
5960
}
6061

packages/vidstack/src/providers/html/html–media-events.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,6 @@ export class HTMLMediaEvents {
167167
private _onLoadedMetadata(event: Event) {
168168
this._attachCanPlayListeners();
169169

170-
// Sync volume state before metadata.
171-
this._notify(
172-
'volume-change',
173-
{
174-
volume: this._media.volume,
175-
muted: this._media.muted,
176-
},
177-
event,
178-
);
179-
180170
this._notify('loaded-metadata', undefined, event);
181171

182172
// Native HLS does not reliably fire `canplay` event.

packages/vidstack/src/providers/vimeo/provider.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ export class VimeoProvider
183183

184184
setVolume(volume) {
185185
this._remote('setVolume', volume);
186+
// Always update muted after volume because setting volume resets muted state.
187+
this._remote('setMuted', peek(this._ctx.$state.muted));
186188
}
187189

188190
setPlaybackRate(rate) {
@@ -296,7 +298,7 @@ export class VimeoProvider
296298
protected override _buildParams(): VimeoParams {
297299
const { $iosControls } = this._ctx,
298300
{ keyDisabled } = this._ctx.$props,
299-
{ controls, muted, playsinline } = this._ctx.$state,
301+
{ controls, playsinline } = this._ctx.$state,
300302
showControls = controls() || $iosControls();
301303
return {
302304
title: this.title,
@@ -307,7 +309,6 @@ export class VimeoProvider
307309
h: this.hash,
308310
keyboard: showControls && !keyDisabled(),
309311
transparent: true,
310-
muted: muted(),
311312
playsinline: playsinline(),
312313
dnt: !this.cookies,
313314
};
@@ -352,7 +353,10 @@ export class VimeoProvider
352353
.then((info) => {
353354
if (!info) return;
354355

355-
const { title, poster, duration, pro } = info;
356+
const { title, poster, duration, pro } = info,
357+
{ $iosControls } = this._ctx,
358+
{ controls } = this._ctx.$state,
359+
showControls = controls() || $iosControls();
356360

357361
this._timeRAF._start();
358362
this._pro.set(pro);
@@ -369,10 +373,6 @@ export class VimeoProvider
369373

370374
this._ctx.delegate._ready(detail, trigger);
371375

372-
const { $iosControls } = this._ctx,
373-
{ controls } = this._ctx.$state,
374-
showControls = controls() || $iosControls();
375-
376376
if (!showControls) {
377377
this._remote('_hideOverlay');
378378
}

0 commit comments

Comments
 (0)