Skip to content

Commit

Permalink
feat(cxl-ui): [cxl-jw-player] fix save position when using a playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
anoblet committed Mar 3, 2023
1 parent ffa54c4 commit e4c8edb
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/cxl-ui/src/components/cxl-jw-player/mixins/StateMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,31 @@ export function StateMixin(BaseClass) {
}

_position() {
const position = localStorage.getItem(`jw-player-${this.mediaId}-position`);
const mediaId = this.mediaId || this._jwPlayer.getPlaylistItem().mediaId;

const position = localStorage.getItem(`jw-player-${mediaId}-position`);

if (position) {
this._jwPlayer.seek(Number(position));
this._jwPlayer.pause();
if (this.mediaId) {
this._setPosition(position);
} else {
this._jwPlayer.on('playlistItem', () => {
this._setPosition(position);
});

this._jwPlayer.playlistItem(this._jwPlayer.getPlaylistIndex());
}
}

this._jwPlayer.on('time', ({ position }) => {
localStorage.setItem(`jw-player-${this.mediaId}-position`, position);
this._jwPlayer.on('seek time', ({ position }) => {
localStorage.setItem(`jw-player-${mediaId}-position`, position);
});
}

_setPosition(position) {
this._jwPlayer.seek(Number(position));
this._jwPlayer.pause();
}
}

return Mixin;
Expand Down

0 comments on commit e4c8edb

Please sign in to comment.