Skip to content

Commit

Permalink
fix(inlineplayer): player autostart setting not respected
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Oct 10, 2022
1 parent fcbd810 commit a9c903d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/components/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,22 @@ const Player: React.FC<Props> = ({

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

playerRef.current.setup({
// player options are untyped
const playerOptions: { [key: string]: unknown } = {
aspectratio: false,
playlist: [deepCopy({ ...item, starttime: startTimeRef.current })],
width: '100%',
height: '100%',
mute: false,
autostart,
repeat: false,
});
};

// only set the autostart parameter when it is defined or it will override the player.defaults autostart setting
if (typeof autostart !== 'undefined') {
playerOptions.autostart = autostart;
}

playerRef.current.setup(playerOptions);

setPlayer(playerRef.current);
attachEvents();
Expand Down
1 change: 1 addition & 0 deletions src/containers/Cinema/Cinema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const Cinema: React.FC<Props> = ({
<PlayerContainer
item={item}
feedId={feedId}
autostart={true}
onPlay={handlePlay}
onPause={handlePause}
onComplete={handleComplete}
Expand Down
3 changes: 3 additions & 0 deletions src/containers/InlinePlayer/InlinePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Props = {
startWatchingButton: React.ReactNode;
isLoggedIn: boolean;
paywall: boolean;
autostart?: boolean;
};

const InlinePlayer: React.FC<Props> = ({
Expand All @@ -40,6 +41,7 @@ const InlinePlayer: React.FC<Props> = ({
startWatchingButton,
isLoggedIn,
paywall,
autostart,
}: Props) => {
const siteName = useConfigStore((s) => s.config.siteName);
const { t } = useTranslation();
Expand All @@ -66,6 +68,7 @@ const InlinePlayer: React.FC<Props> = ({
<PlayerContainer
item={item}
feedId={feedId}
autostart={autostart}
onPlay={onPlay}
onPause={onPause}
onComplete={onComplete}
Expand Down
4 changes: 2 additions & 2 deletions src/containers/PlayerContainer/PlayerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Player from '#src/components/Player/Player';
import type { JWPlayer } from '#types/jwplayer';
import { useWatchHistoryStore } from '#src/stores/WatchHistoryStore';
import { VideoProgressMinMax } from '#src/config';
import useQueryParam from '#src/hooks/useQueryParam';

type Props = {
item: PlaylistItem;
Expand All @@ -23,6 +22,7 @@ type Props = {
liveStartDateTime?: string | null;
liveEndDateTime?: string | null;
liveFromBeginning?: boolean;
autostart?: boolean;
};

const PlayerContainer: React.FC<Props> = ({
Expand All @@ -36,8 +36,8 @@ const PlayerContainer: React.FC<Props> = ({
liveEndDateTime,
liveFromBeginning,
liveStartDateTime,
autostart,
}: Props) => {
const autostart = useQueryParam('play') === '1';
const { player, features } = useConfigStore((s) => s.config);
const continueWatchingList = features?.continueWatchingList;
const watchHistoryEnabled = !!continueWatchingList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const MediaMovie: ScreenComponent<PlaylistItem> = ({ data, isLoading }) => {
feedId={feedId ?? undefined}
startWatchingButton={startWatchingButton}
paywall={isLocked(accessModel, isLoggedIn, hasSubscription, data)}
autostart={play || undefined}
/>
) : (
<Cinema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const MediaSeriesEpisode: ScreenComponent<PlaylistItem> = ({ data }) => {
feedId={feedId ?? undefined}
startWatchingButton={startWatchingButton}
paywall={isLocked(accessModel, isLoggedIn, hasSubscription, episodeItem)}
autostart={play || undefined}
/>
) : (
<Cinema
Expand Down

0 comments on commit a9c903d

Please sign in to comment.