Skip to content

Commit

Permalink
fix(player): fix autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Aug 6, 2021
1 parent d327e24 commit 3e7d7b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/containers/Cinema/Cinema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ const Cinema: React.FC<Props> = ({ item, onPlay, onPause, onComplete, onUserActi
const { watchHistory } = watchHistoryStore.getRawState();
const watchHistoryItem = watchHistory.find(({ mediaid }) => mediaid === item.mediaid);

if (watchHistoryItem && enableWatchHistory && watchHistoryItem.progress > VideoProgressMinMax.Min && watchHistoryItem.progress < VideoProgressMinMax.Max) {
if (
watchHistoryItem &&
enableWatchHistory &&
watchHistoryItem.progress > VideoProgressMinMax.Min &&
watchHistoryItem.progress < VideoProgressMinMax.Max
) {
seekToRef.current = watchHistoryItem.progress * watchHistoryItem.duration;
} else {
seekToRef.current = -1;
Expand All @@ -124,14 +129,14 @@ const Cinema: React.FC<Props> = ({ item, onPlay, onPause, onComplete, onUserActi
}

// load new item
playerRef.current.load([deepCopy(item)]);
playerRef.current.setConfig({ playlist: [deepCopy(item)], autostart: true });
calculateWatchHistoryProgress();
};

const initializePlayer = () => {
if (!window.jwplayer || !playerElementRef.current) return;

playerRef.current = window.jwplayer(playerElementRef.current);
playerRef.current = window.jwplayer(playerElementRef.current) as JWPlayer;

playerRef.current.setup({
playlist: [deepCopy(item)],
Expand Down
1 change: 1 addition & 0 deletions types/jwplayer.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type JWPlayer = jwplayer.JWPlayer & {
on(event: 'userActive' | 'userInactive', callback: () => void);
off(event: 'userActive' | 'userInactive', callback: () => void);
setConfig({ playlist, autostart });
};

0 comments on commit 3e7d7b4

Please sign in to comment.