@@ -50,8 +50,15 @@ FvpPlayer useFvpPlayer(BuildContext context) {
5050 final List <Subtitle > externalSubtitles = useMemoized (
5151 () => currentPlay? .file.subtitles ?? [], [currentPlay? .file.subtitles]);
5252
53+ final initValue = useState (false );
54+
55+ final isInitializing = useState (false );
56+
57+ Future <void > init () async => initValue.value = true ;
58+
5359 final controller = useMemoized (() {
5460 if (file == null ) return VideoPlayerController .networkUrl (Uri .parse ('' ));
61+ isInitializing.value = true ;
5562 final storage = useStorageStore ().findById (file.storageId);
5663 final auth = storage? .getAuth ();
5764 switch (checkDataSourceType (file)) {
@@ -75,21 +82,28 @@ FvpPlayer useFvpPlayer(BuildContext context) {
7582 httpHeaders: auth != null ? {'authorization' : auth} : {},
7683 );
7784 }
78- }, [file]);
85+ }, [file, initValue.value ]);
7986
8087 useEffect (() {
8188 () async {
8289 if (controller.dataSource.isEmpty) return ;
83- await controller.initialize ();
84- await controller.setLooping (repeat == Repeat .one ? true : false );
85- await controller.setVolume (isMuted ? 0 : volume / 100 );
90+
91+ try {
92+ await controller.initialize ();
93+ await controller.setLooping (repeat == Repeat .one ? true : false );
94+ await controller.setVolume (isMuted ? 0 : volume / 100 );
95+ } catch (e) {
96+ logger ('Error initializing player: $e ' );
97+ }
98+
99+ isInitializing.value = false ;
86100 }();
87101
88102 return () {
89103 controller.dispose ();
90104 externalSubtitle.value = null ;
91105 };
92- }, [controller]);
106+ }, [controller, initValue.value ]);
93107
94108 useEffect (() => controller.dispose, []);
95109
@@ -222,6 +236,9 @@ FvpPlayer useFvpPlayer(BuildContext context) {
222236
223237 Future <void > play () async {
224238 await useAppStore ().updateAutoPlay (true );
239+ if (! controller.value.isInitialized && ! isInitializing.value) {
240+ init ();
241+ }
225242 controller.play ();
226243 }
227244
@@ -260,6 +277,7 @@ FvpPlayer useFvpPlayer(BuildContext context) {
260277
261278 return FvpPlayer (
262279 controller: controller,
280+ isInitializing: isInitializing.value,
263281 isPlaying: isPlaying,
264282 externalSubtitle: externalSubtitle,
265283 externalSubtitles: externalSubtitles,
0 commit comments