Skip to content

Commit

Permalink
fix(player): fix player error after playing the same item a second time
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Aug 4, 2021
1 parent 395b9e8 commit ed31555
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/containers/Cinema/Cinema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { watchHistoryStore, useWatchHistory } from '../../stores/WatchHistorySto
import { ConfigContext } from '../../providers/ConfigProvider';
import { addScript } from '../../utils/dom';
import useOttAnalytics from '../../hooks/useOttAnalytics';
import { deepCopy } from '../../utils/collection';

import styles from './Cinema.module.scss';

Expand Down Expand Up @@ -64,15 +65,7 @@ const Cinema: React.FC<Props> = ({ item, onPlay, onPause, onComplete, onUserActi
}

// load new item
playerRef.current.load([
{
mediaid: item.mediaid,
image: item.image,
title: item.title,
description: item.description,
sources: item.sources.map((source) => ({ ...source })),
},
]);
playerRef.current.load([deepCopy(item)]);
};

const initializePlayer = () => {
Expand All @@ -85,7 +78,7 @@ const Cinema: React.FC<Props> = ({ item, onPlay, onPause, onComplete, onUserActi
playerRef.current = window.jwplayer(playerElementRef.current);

playerRef.current.setup({
playlist: [item],
playlist: [deepCopy(item)],
aspect: false,
width: '100%',
height: '100%',
Expand Down
8 changes: 8 additions & 0 deletions src/utils/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ const checkConsentsFromValues = (publisherConsents: Consent[], consents: Record<
return { customerConsents, consentsErrors };
};

const deepCopy = (obj: unknown) => {
if (Array.isArray(obj) || (typeof obj === 'object' && obj !== null)) {
return JSON.parse(JSON.stringify(obj));
}
return obj;
};

export {
getFiltersFromConfig,
getFiltersFromSeries,
Expand All @@ -138,4 +145,5 @@ export {
formatConsentsFromValues,
extractConsentValues,
checkConsentsFromValues,
deepCopy,
};

0 comments on commit ed31555

Please sign in to comment.