Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/app/components/MediaLoader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,23 @@ const MediaContainer = ({
eventMapping,
}: MediaContainerProps) => {
const playerElementRef = useRef<HTMLDivElement>(null);

const isAudio = isAudioPlayer(playerConfig);

useEffect(() => {
try {
window.requirejs(['bump-4'], async (Bump: BumpType) => {
const {
statsObject: { episodePID },
} = playerConfig;
let timestamp;
if (episodePID) {
timestamp = window?.localStorage?.getItem(episodePID);
}
if (timestamp) {
playerConfig.startTime = parseInt(timestamp, 10);
}

if (playerElementRef?.current && playerConfig) {
const mediaPlayer = Bump.player(
playerElementRef.current,
Expand Down Expand Up @@ -174,8 +186,15 @@ const MediaContainer = ({
);
});
}

mediaPlayer.load();
window.addEventListener('beforeunload', () => {
if (mediaPlayer.currentTime() > 30 && episodePID) {
localStorage.setItem(
episodePID,
mediaPlayer.currentTime().toString(),
);
}
});
}
});
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions src/app/components/MediaLoader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type PlayerConfig = {
plugins?: {
toLoad: { html: string; playerOnly?: boolean }[];
};
startTime: number;
};

export type PlayerUiConfig = {
Expand Down Expand Up @@ -155,6 +156,8 @@ export type Player = {
pause: () => void;
previous: () => void;
next: () => void;
currentTime: () => number;
identifier: () => string;
bind: (event: MediaPlayerEvents, callback: (e: SMPEvent) => void) => void;
loadPlugin: (
pluginName: { [key: string]: string },
Expand Down
Loading