private async void PrepareWindowToWork() { var cameras = await _camerasService.GetCameras(); MonitoringImages.Clear(); foreach (var camera in cameras) { var monitoringImage = new MonitoringImage { CameraName = camera.Name, CameraId = camera.Id.ToString(), Url = camera.Url, GridWidth = HalfWidth - 20, GridHeight = HalfHeight, IsRecordSetupNeed = true, IsRecording = true }; MonitoringImages.Add(monitoringImage); } RaisePropertyChanged("MonitoringImages"); StartAllCameras(); }
private void CaptureVideo_Frame(object sender, NewFrameEventArgs eventArgs) { var monitoringImage = MonitoringImages.FirstOrDefault(mi => mi.Url == ((MJPEGStream)sender).Source); if (monitoringImage != null) { try { BitmapImage bitmapImage; using (var bitmap = (Bitmap)eventArgs.Frame.Clone()) { bitmapImage = bitmap.ToBitmapImage(); if (monitoringImage.IsRecordSetupNeed) { monitoringImage.IsRecordSetupNeed = false; monitoringImage.VideoRecordingService.SetUpRecordingEngine(bitmap.Width, bitmap.Height, monitoringImage.CameraName); } if (monitoringImage.IsRecording) { monitoringImage.VideoRecordingService.StartVideoRecording(bitmap); } } bitmapImage.Freeze(); Dispatcher.CurrentDispatcher.Invoke(() => monitoringImage.Image = bitmapImage); } catch (Exception ex) { MessageBox.Show("Oppps, video stream have fallen down.", "Exception", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void StartLastAddedCamera() { _videoSource = new MJPEGStream(IpCameraUrls.Last().ImageSourcePath); var image = MonitoringImages.FirstOrDefault(mi => mi.Url == IpCameraUrls.Last().ImageSourcePath); image.VideoSource = _videoSource; _videoSource.NewFrame += CaptureVideo_Frame; _videoSource.Start(); }
public async void AddNewCamera() { var newCameraView = new NewCameraView(); newCameraView.ShowDialog(); var viewModel = ((NewCameraViewModel)newCameraView.DataContext); var url = viewModel.IpCameraUrl; var cameraName = viewModel.CameraName; if (url != null) { if (await _camerasService.IsCameraExists(url)) { MessageBox.Show("Url that you are trying to add is already exists.", "Exception", MessageBoxButton.OK, MessageBoxImage.Information); return; } IpCameraUrls.Add(new CameraScreen { ImageSourcePath = url }); RaisePropertyChanged("IpCameraUrls"); var monitoringImage = new MonitoringImage(url, HalfWidth - 20, HalfHeight); monitoringImage.VideoRecordingService = new VideoRecordingService(); monitoringImage.CameraName = cameraName; monitoringImage.IsRecording = true; MonitoringImages.Add(monitoringImage); var camera = new Camera { Url = url, Name = cameraName }; _camerasService.SaveNewCamera(camera); monitoringImage.CameraId = camera.Id.ToString(); StartLastAddedCamera(); } }