@@ -31,19 +31,19 @@ pub struct VideoPlayer {
3131 frame : State < Option < VideoFrame > > ,
3232 playback : State < PlaybackState > ,
3333 forwarder : State < Option < OwnedTaskHandle > > ,
34- source : State < Option < VideoSource > > ,
34+ source : State < VideoSource > ,
3535 position : State < Duration > ,
3636 duration : State < Option < Duration > > ,
3737 client : State < Option < VideoClient > > ,
3838}
3939
4040impl VideoPlayer {
41- pub fn create ( ) -> Self {
41+ pub fn create ( source : VideoSource ) -> Self {
4242 Self {
4343 frame : State :: create ( None ) ,
4444 playback : State :: create ( PlaybackState :: Idle ) ,
4545 forwarder : State :: create ( None ) ,
46- source : State :: create ( None ) ,
46+ source : State :: create ( source ) ,
4747 position : State :: create ( Duration :: ZERO ) ,
4848 duration : State :: create ( None ) ,
4949 client : State :: create ( None ) ,
@@ -126,10 +126,7 @@ impl VideoPlayer {
126126 self . client . set ( None ) ;
127127 self . playback . set ( PlaybackState :: Loading ) ;
128128
129- let Some ( source) = self . source . peek ( ) . clone ( ) else {
130- self . forwarder . set ( None ) ;
131- return ;
132- } ;
129+ let source = self . source . peek ( ) . clone ( ) ;
133130 let player = * self ;
134131 let handle = spawn ( async move {
135132 Timer :: after ( SEEK_DEBOUNCE ) . await ;
@@ -175,8 +172,7 @@ impl VideoPlayer {
175172pub fn use_video ( init : impl FnOnce ( ) -> VideoSource + ' static ) -> VideoPlayer {
176173 use_hook ( move || {
177174 let source = init ( ) ;
178- let mut player = VideoPlayer :: create ( ) ;
179- player. source . set ( Some ( source. clone ( ) ) ) ;
175+ let mut player = VideoPlayer :: create ( source. clone ( ) ) ;
180176 player. playback . set ( PlaybackState :: Loading ) ;
181177 let handle = spawn ( player. run ( source, Duration :: ZERO ) ) . owned ( ) ;
182178 player. forwarder . set ( Some ( handle) ) ;
0 commit comments