fix: player supports older browsers
This commit is contained in:
1 parent
91f8b4fc1e
commit
62aa336a7d
10 files changed
+161
-122
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
import { FC, useRef, useState } from 'react';
|
||||
import { MediaPlayer, MediaPlayerInstance, MediaProvider, Track, VideoSrc } from '@vidstack/react';
|
||||
import { defaultLayoutIcons, DefaultVideoLayout } from '@vidstack/react/player/layouts/default';
|
||||
import { PlyrLayout, plyrLayoutIcons } from '@vidstack/react/player/layouts/plyr';
|
||||
|
||||
import CaptionsMenu from './components/CaptionsMenu';
|
||||
import VideosMenu from './components/VideosMenu';
|
||||
@@ -10,10 +10,10 @@ import VideosMenu from './components/VideosMenu';
|
||||
interface Props {
|
||||
subtitles: Source[];
|
||||
videos: Source[];
|
||||
onClose: () => void;
|
||||
onReady: () => void;
|
||||
}
|
||||
|
||||
const Player: FC<Props> = ({ videos, subtitles }) => {
|
||||
const Player: FC<Props> = ({ videos, subtitles, onReady }) => {
|
||||
const [index, setIndex] = useState(0);
|
||||
|
||||
const player = useRef<MediaPlayerInstance>(null);
|
||||
@@ -23,6 +23,7 @@ const Player: FC<Props> = ({ videos, subtitles }) => {
|
||||
return (
|
||||
<MediaPlayer
|
||||
autoPlay
|
||||
onCanPlay={onReady}
|
||||
load='eager'
|
||||
storage='movie-advisor'
|
||||
ref={player}
|
||||
@@ -34,17 +35,15 @@ const Player: FC<Props> = ({ videos, subtitles }) => {
|
||||
<Track key={track.name} src={track.src} kind='subtitles' label={track.name} type='srt' default />
|
||||
))}
|
||||
</MediaProvider>
|
||||
<DefaultVideoLayout
|
||||
colorScheme='dark'
|
||||
icons={defaultLayoutIcons}
|
||||
<PlyrLayout
|
||||
icons={plyrLayoutIcons}
|
||||
slots={{
|
||||
playLargeButton: null,
|
||||
afterVolumeSlider: <ul className='w-2' />,
|
||||
beforeSettings: <CaptionsMenu />,
|
||||
settings: <VideosMenu source={source} sources={videos} onChange={setIndex} />,
|
||||
settingsMenu: null,
|
||||
captionButton: null,
|
||||
googleCastButton: null,
|
||||
beforeSettingsMenu: Boolean(videos.length > 1) && (
|
||||
<VideosMenu source={source} sources={videos} onChange={setIndex} />
|
||||
),
|
||||
afterSettingsMenu: Boolean(subtitles.length) && <CaptionsMenu />
|
||||
captionsButton: null
|
||||
}}
|
||||
/>
|
||||
</MediaPlayer>
|
||||
|
||||
+6
-1
@@ -14,7 +14,12 @@ const CaptionsMenu = () => {
|
||||
options={tracks.map((track) => ({ label: track.label, onClick: () => track.select() }))}
|
||||
isChecked={({ label }) => (label === 'Off' ? !track : label === track?.label)}
|
||||
>
|
||||
{track ? <ClosedCaptionsOnIcon className={cn('vds-icon')} /> : <ClosedCaptionsIcon className={cn('vds-icon')} />}
|
||||
{track ? (
|
||||
<ClosedCaptionsOnIcon className={cn('vds-icon !transform-none !size-5')} />
|
||||
) : (
|
||||
<ClosedCaptionsIcon className={cn('vds-icon !transform-none !size-5')} />
|
||||
)}
|
||||
<span className={cn('plyr__tooltip')}>Subtitles</span>
|
||||
</PlayerMenu>
|
||||
);
|
||||
};
|
||||
|
||||
+4
-4
@@ -13,17 +13,17 @@ interface Props {
|
||||
}
|
||||
|
||||
const PlayerMenu: FC<Props> = ({ children, options, isChecked }) => (
|
||||
<Menu.Root className={cn('vds-menu')}>
|
||||
<Menu.Button className={cn('vds-menu-button vds-button')} aria-label='Settings'>
|
||||
<Menu.Root className={cn('plyr__menu')}>
|
||||
<Menu.Button className={cn('plyr__controls__item plyr__control')} aria-expanded={false}>
|
||||
{children}
|
||||
</Menu.Button>
|
||||
<Menu.Items className={cn('vds-menu-items !p-2')} placement='top end' offset={0}>
|
||||
<Menu.Items className={cn('plyr__menu__container !p-0')} placement='top end' offset={0}>
|
||||
<Menu.RadioGroup>
|
||||
{options.map((option) => (
|
||||
<Menu.Radio
|
||||
key={option.label}
|
||||
title={option.label}
|
||||
className='flex w-64 cursor-pointer items-center gap-2 truncate p-2'
|
||||
className='!m-0 flex w-64 cursor-pointer items-center gap-2 truncate p-2'
|
||||
onClick={option.onClick}
|
||||
>
|
||||
<CheckIcon className={cn('vds-icon shrink-0', { invisible: !isChecked(option) })} size={16} />
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ const VideosMenu: FC<Props> = ({ sources, source, onChange }) => (
|
||||
options={sources.map(({ name }, index) => ({ label: name, onClick: () => onChange(index) }))}
|
||||
isChecked={({ label }) => source.name === label}
|
||||
>
|
||||
<PlaylistIcon className={cn('vds-icon')} />
|
||||
<PlaylistIcon className={cn('vds-icon !transform-none')} />
|
||||
<span className={cn('plyr__tooltip')}>Playlist</span>
|
||||
</PlayerMenu>
|
||||
);
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { Loader } from 'lucide-react';
|
||||
import dynamic from 'next/dynamic';
|
||||
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
@@ -15,14 +17,22 @@ interface Props extends InstanceProps<void> {
|
||||
}
|
||||
|
||||
const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => {
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
|
||||
const {
|
||||
data: { subtitles, videos },
|
||||
error,
|
||||
isFetched,
|
||||
isLoading
|
||||
} = useFiles(magnet);
|
||||
|
||||
const { toast } = useToast();
|
||||
|
||||
if (error) {
|
||||
toast({ description: 'Download Failed: unable to retrieve the video' });
|
||||
onResolve();
|
||||
}
|
||||
|
||||
if (isFetched && !videos.length) {
|
||||
toast({ description: 'This torrent doesn\'t contain any compatible video files' });
|
||||
onResolve();
|
||||
@@ -32,9 +42,18 @@ const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => {
|
||||
<Modal className='overflow-hidden rounded-lg border-none bg-black p-0' onClose={onResolve}>
|
||||
<div className='relative w-full overflow-hidden pt-[56.25%]'>
|
||||
<div className='absolute left-0 top-0 size-full'>
|
||||
<Player subtitles={subtitles} videos={videos} onClose={onResolve} />
|
||||
<Player subtitles={subtitles} videos={videos} onReady={() => setIsReady(true)} />
|
||||
</div>
|
||||
{isLoading && <img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} />}
|
||||
{(!isReady || isLoading) && (
|
||||
<div className='absolute left-0 top-0 size-full'>
|
||||
<img src={backdrop} className='absolute left-0 top-0 size-full' alt={title} />
|
||||
<div className='absolute left-0 top-0 flex size-full items-center justify-center bg-black/80'>
|
||||
<div className='animate-spin'>
|
||||
<Loader color='white' />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user