@@ -269,9 +269,9 @@ protected virtual void Dispose(bool disposing)
269269 }
270270 }
271271
272+ // Ta metoda wywoła się, gdy stream się "urwie" lub skończy
272273 private void VideoInWindowPlayer_MediaEnded ( object sender , RoutedEventArgs e )
273274 {
274- // Stream się zakończył (np. serwer zerwał połączenie) - próbujemy połączyć ponownie
275275 ReloadStream ( ) ;
276276 }
277277
@@ -281,23 +281,18 @@ private void VideoInWindowPlayer_MediaFailed(object sender, ExceptionRoutedEvent
281281 ReloadStream ( ) ;
282282 }
283283
284- private void ReloadStream ( )
284+ private async void ReloadStream ( )
285285 {
286- // Check if user paused video manually
287- if ( isVideoPaused || ! mediaPlayerIsPlaying ) return ;
286+ if ( isVideoPaused ) return ;
288287
289- Dispatcher . Invoke ( ( ) =>
290- {
291- // This will force WPF to reconnect to the stream
292- var currentSource = videoInWindowPlayer . Source ;
288+ await Task . Delay ( 1 ) ;
293289
294- if ( currentSource != null )
295- {
296- videoInWindowPlayer . Source = null ;
297- videoInWindowPlayer . Source = currentSource ;
298- videoInWindowPlayer . Play ( ) ;
299- }
300- } ) ;
290+ if ( isVideoPaused ) return ;
291+
292+ var currentTempSource = videoInWindowPlayer . Source ;
293+ videoInWindowPlayer . Source = null ;
294+ videoInWindowPlayer . Source = currentTempSource ;
295+ videoInWindowPlayer . Play ( ) ;
301296 }
302297
303298 public TimeSpan GetCurrentVideoPosition ( )
0 commit comments