@@ -12,6 +12,7 @@ import PlayerToaster from '@/fronted/components/PlayerToaster';
1212import UrlUtil from '@/common/utils/UrlUtil' ;
1313import StrUtil from '@/common/utils/str-util' ;
1414import ReactPlayer from 'react-player/file' ;
15+ import { useNavigate } from 'react-router-dom' ;
1516
1617const api = window . electron ;
1718
@@ -26,7 +27,8 @@ export default function Player({ className }: { className?: string }): ReactElem
2627 updateExactPlayTime,
2728 setDuration,
2829 seekTo,
29- playbackRate
30+ playbackRate,
31+ autoPlayNext
3032 } = usePlayerController (
3133 useShallow ( ( state ) => ( {
3234 playing : state . playing ,
@@ -38,7 +40,8 @@ export default function Player({ className }: { className?: string }): ReactElem
3840 updateExactPlayTime : state . updateExactPlayTime ,
3941 setDuration : state . setDuration ,
4042 seekTo : state . seekTo ,
41- playbackRate : state . playbackRate
43+ playbackRate : state . playbackRate ,
44+ autoPlayNext : state . autoPlayNext
4245 } ) )
4346 ) ;
4447 const videoPath = useFile ( ( s ) => s . videoPath ) ;
@@ -47,6 +50,7 @@ export default function Player({ className }: { className?: string }): ReactElem
4750 const videoLoaded = useFile ( ( s ) => s . videoLoaded ) ;
4851 const playerRef = useRef < ReactPlayer > ( null ) ;
4952 const playerRefBackground = useRef < HTMLCanvasElement > ( null ) ;
53+ const navigate = useNavigate ( ) ;
5054 let lastFile : string | undefined ;
5155
5256 const fullScreen = useLayout ( ( s ) => s . fullScreen ) ;
@@ -182,6 +186,24 @@ export default function Player({ className }: { className?: string }): ReactElem
182186 lastFile = file ;
183187 } ;
184188
189+ const handleAutoPlayNext = async ( ) => {
190+ if ( ! autoPlayNext || ! videoId ) {
191+ return ;
192+ }
193+
194+ try {
195+ const nextVideo = await api . call ( 'watch-history/get-next-video' , videoId ) ;
196+ if ( nextVideo ) {
197+ console . log ( 'Auto playing next video:' , nextVideo . fileName ) ;
198+ navigate ( `/player/${ nextVideo . id } ` ) ;
199+ } else {
200+ console . log ( 'No next video found' ) ;
201+ }
202+ } catch ( error ) {
203+ console . error ( 'Failed to get next video:' , error ) ;
204+ }
205+ } ;
206+
185207 console . log ( 'videoPath' , videoPath ) ;
186208 const render = ( ) : ReactElement => {
187209 if ( StrUtil . isBlank ( videoPath ) ) {
@@ -230,6 +252,7 @@ export default function Player({ className }: { className?: string }): ReactElem
230252 await jumpToHistoryProgress ( videoPath ) ;
231253 loadedVideo ( videoPath ) ;
232254 } }
255+ onEnded = { handleAutoPlayNext }
233256 />
234257 { ! fullScreen && ( ! showControlPanel && (
235258 < PlayerControlPanel
0 commit comments