@@ -262,6 +262,7 @@ private async Task EvaluateVideoFrameAsync()
262262 public async Task StartLiveStream ( )
263263 {
264264 Debug . WriteLine ( "StartLiveStream" ) ;
265+ await CleanupCameraAsync ( ) ;
265266
266267 try
267268 {
@@ -290,8 +291,9 @@ public async Task StartLiveStream()
290291
291292 public async Task ChangeLiveStream ( )
292293 {
293- await CleanupCameraAsync ( ) ;
294294 Debug . WriteLine ( "ChangeLiveStream" ) ;
295+ await CleanupCameraAsync ( ) ;
296+
295297 SaveEnabled = false ;
296298
297299 // If webcam hasn't been initialized, bail.
@@ -300,7 +302,11 @@ public async Task ChangeLiveStream()
300302 try
301303 {
302304 // Check that SCI hasn't < 0
303- if ( _appModel . SelectedCameraIndex < 0 ) _appModel . SelectedCameraIndex = 0 ;
305+ if ( _appModel . SelectedCameraIndex < 0 )
306+ {
307+ _appModel . SelectedCameraIndex = 0 ;
308+ return ;
309+ }
304310 _selectedMediaFrameSourceGroup = _mediaFrameSourceGroupList [ _appModel . SelectedCameraIndex ] ;
305311
306312 // Create MediaCapture and its settings
@@ -312,6 +318,7 @@ public async Task ChangeLiveStream()
312318 StreamingCaptureMode = StreamingCaptureMode . Video
313319 } ;
314320 _mediaCapture = new MediaCapture ( ) ;
321+ Debug . WriteLine ( "initalized mediacapture" ) ;
315322 await _mediaCapture . InitializeAsync ( settings ) ;
316323 displayRequest . RequestActive ( ) ;
317324
@@ -398,7 +405,12 @@ private async Task CleanupCameraAsync()
398405 {
399406 if ( isPreviewing )
400407 {
401- await _mediaCapture . StopPreviewAsync ( ) ;
408+ try
409+ {
410+ await _mediaCapture . StopPreviewAsync ( ) ;
411+ }
412+ catch ( Exception e ) { Debug . WriteLine ( "CleanupCamera: " + e . Message ) ; }
413+
402414 isPreviewing = false ;
403415 }
404416 await DispatcherHelper . RunAsync ( ( ) =>
@@ -416,11 +428,7 @@ await DispatcherHelper.RunAsync(() =>
416428 m . Dispose ( ) ;
417429 } ) ;
418430 }
419- if ( videoEffect != null )
420- {
421- videoEffect = null ;
422- }
423- if ( videoEffectDefinition != null ) videoEffectDefinition = null ;
431+
424432 }
425433
426434 catch ( Exception ex )
0 commit comments