Skip to content

Commit

Permalink
Fixed Media syncing when pause event is emitted by a player immediate…
Browse files Browse the repository at this point in the history
…ly before ended (#672)

Co-authored-by: James Hunt <[email protected]>
  • Loading branch information
huntj88 and James Hunt committed Aug 10, 2023
1 parent 2584bf6 commit e17b1fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/live-share-media/src/MediaPlayerSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export class MediaPlayerSynchronizer extends EventEmitter {
// needed because cannot tell if its a user initiated event, so disallow pause
if (
this._expectedPlaybackState === "playing" &&
!this._mediaSession.coordinator.isSuspended
!this._mediaSession.coordinator.isSuspended &&
// some players have ended, but emit a pause event immediately before ended event. Do not play if ended
!this._player.ended
) {
this._player.play();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ export class AzureMediaPlayer extends EventTarget {
}

get ended() {
return this._player.ended();
// It is important that ended is reported properly.
// Some players like to reset at the end of playback and set ended to false.
return this._player.ended() || this._track.ended;
}

get autoplay() {
Expand Down Expand Up @@ -357,9 +359,6 @@ export class AzureMediaPlayer extends EventTarget {
this._applySkipTo(false);
break;
case PlayerEvent.ended:
this.load();
this.play();
this.pause();
this._stopPositionTracker();
this._track.ended = true;
this._track.playing = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export class AzureMediaPlayer extends EventTarget {
}

get ended(): boolean {
return this._player.ended();
// It is important that ended is reported properly.
// Some players like to reset at the end of playback and set ended to false.
return this._player.ended() || this._track.ended;
}

get autoplay(): boolean {
Expand Down Expand Up @@ -372,9 +374,6 @@ export class AzureMediaPlayer extends EventTarget {
// this._applySkipTo(false);
break;
case PlayerEvent.ended:
this.load();
this.play();
this.pause();
this._stopPositionTracker();
this._track.ended = true;
this._track.playing = false;
Expand Down

0 comments on commit e17b1fe

Please sign in to comment.