@@ -28,6 +28,7 @@ public AppViewModel()
2828 SaveCommand = new RelayCommand ( this . SaveOutput ) ;
2929 MediaSourceCommand = new RelayCommand < string > ( SetMediaSource ) ;
3030 LiveStreamCommand = new RelayCommand ( async ( ) => await StartWebcamStream ( ) ) ;
31+ ChangeMediaInputCommand = new RelayCommand ( async ( ) => await ChangeMediaInput ( ) ) ;
3132 }
3233
3334 Windows . Media . Capture . MediaCapture _mediaCapture ;
@@ -60,6 +61,7 @@ public ICommand SaveCommand
6061
6162 public ICommand MediaSourceCommand { get ; set ; }
6263 public ICommand LiveStreamCommand { get ; set ; }
64+ public ICommand ChangeMediaInputCommand { get ; set ; }
6365
6466 public event PropertyChangedEventHandler PropertyChanged ;
6567
@@ -93,42 +95,7 @@ public async Task StartWebcamStream()
9395 }
9496
9597 _appModel . CameraNamesList = _mediaFrameSourceGroupList . Select ( group => group . DisplayName ) ;
96-
97- // UICmbCamera_SelectionChanged
98- try
99- {
100- _selectedMediaFrameSourceGroup = _mediaFrameSourceGroupList [ _appModel . SelectedCameraIndex ] ;
101-
102- // Create MediaCapture and its settings
103- _mediaCapture = new MediaCapture ( ) ;
104- var settings = new MediaCaptureInitializationSettings
105- {
106- SourceGroup = _selectedMediaFrameSourceGroup ,
107- PhotoCaptureSource = PhotoCaptureSource . Auto ,
108- MemoryPreference = MediaCaptureMemoryPreference . Cpu ,
109- StreamingCaptureMode = StreamingCaptureMode . Video
110- } ;
111-
112- // Initialize MediaCapture
113- await _mediaCapture . InitializeAsync ( settings ) ;
114- await LoadModelAsync ( ) ;
115-
116- // Initialize VideoEffect
117- var videoEffectDefinition = new VideoEffectDefinition ( "StyleTransferEffectComponent.StyleTransferVideoEffect" ) ;
118- IMediaExtension videoEffect = await _mediaCapture . AddVideoEffectAsync ( videoEffectDefinition , MediaStreamType . VideoPreview ) ;
119- // Try loading the model here and passing as a property instead
120- videoEffect . SetProperties ( new PropertySet ( ) {
121- { "Model" , m_model } ,
122- { "Session" , m_session } ,
123- { "InputImageDescription" , _inputImageDescription } ,
124- { "OutputImageDescription" , _outputImageDescription } } ) ;
125-
126- StartPreview ( ) ;
127- }
128- catch ( Exception ex )
129- {
130- Debug . WriteLine ( ex . ToString ( ) ) ;
131- }
98+ _appModel . SelectedCameraIndex = 0 ;
13299 }
133100
134101 private async Task LoadModelAsync ( )
@@ -245,5 +212,44 @@ private void StartPreview()
245212 UIOutputMediaPlayerElement.Visibility = Visibility.Visible;*/
246213
247214 }
215+
216+ private async Task ChangeMediaInput ( )
217+ {
218+ // UICmbCamera_SelectionChanged
219+ try
220+ {
221+ _selectedMediaFrameSourceGroup = _mediaFrameSourceGroupList [ _appModel . SelectedCameraIndex ] ;
222+
223+ // Create MediaCapture and its settings
224+ _mediaCapture = new MediaCapture ( ) ;
225+ var settings = new MediaCaptureInitializationSettings
226+ {
227+ SourceGroup = _selectedMediaFrameSourceGroup ,
228+ PhotoCaptureSource = PhotoCaptureSource . Auto ,
229+ MemoryPreference = MediaCaptureMemoryPreference . Cpu ,
230+ StreamingCaptureMode = StreamingCaptureMode . Video
231+ } ;
232+
233+ // Initialize MediaCapture
234+ await _mediaCapture . InitializeAsync ( settings ) ;
235+ await LoadModelAsync ( ) ;
236+
237+ // Initialize VideoEffect
238+ var videoEffectDefinition = new VideoEffectDefinition ( "StyleTransferEffectComponent.StyleTransferVideoEffect" ) ;
239+ IMediaExtension videoEffect = await _mediaCapture . AddVideoEffectAsync ( videoEffectDefinition , MediaStreamType . VideoPreview ) ;
240+ // Try loading the model here and passing as a property instead
241+ videoEffect . SetProperties ( new PropertySet ( ) {
242+ { "Model" , m_model } ,
243+ { "Session" , m_session } ,
244+ { "InputImageDescription" , _inputImageDescription } ,
245+ { "OutputImageDescription" , _outputImageDescription } } ) ;
246+
247+ StartPreview ( ) ;
248+ }
249+ catch ( Exception ex )
250+ {
251+ Debug . WriteLine ( ex . ToString ( ) ) ;
252+ }
253+ }
248254 }
249255}
0 commit comments