-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
97 lines (78 loc) · 2.95 KB
/
MainWindow.xaml.cs
File metadata and controls
97 lines (78 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Windows;
using LibVLCSharp.Shared;
using RTSPDeck.Models;
using RTSPDeck.Services;
using System.Windows.Controls;
namespace RTSPDeck
{
public partial class MainWindow : Window
{
private LibVLC _libVLC;
private CameraManager _cameraManager;
private void OpenManageCameras_Click(object sender, RoutedEventArgs e)
{
var manageWindow = new ManageCamerasWindow();
manageWindow.ShowDialog();
_cameraManager = new CameraManager();
LoadCameraFeeds();
}
private void RefreshFeeds_Click(object sender, RoutedEventArgs e)
{
_cameraManager = new CameraManager();
LoadCameraFeeds();
}
public MainWindow()
{
InitializeComponent();
Core.Initialize();
_libVLC = new LibVLC();
_cameraManager = new CameraManager();
LoadCameraFeeds();
if (AutoStartCheckBox != null)
{
AutoStartCheckBox.IsChecked = AutoStartService.IsAutoStartEnabled();
AutoStartCheckBox.Checked += (_, __) => AutoStartService.EnableAutoStart();
AutoStartCheckBox.Unchecked += (_, __) => AutoStartService.DisableAutoStart();
}
}
private void LoadCameraFeeds()
{
VideoGrid.Children.Clear();
var feeds = _cameraManager.Feeds;
int count = feeds.Count;
if (count == 0)
{
MessageBox.Show("No camera feeds configured. Use Manage Cameras to add them.", "RTSPDeck", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
int columns = (int)Math.Ceiling(Math.Sqrt(count));
int rows = (int)Math.Ceiling((double)count / columns);
VideoGrid.Columns = columns;
VideoGrid.Rows = rows;
foreach (var feed in feeds)
{
var mediaPlayer = new MediaPlayer(_libVLC);
mediaPlayer.EncounteredError += (s, e) =>
{
MessageBox.Show($"Playback error for feed: {feed.Name}");
};
string rtspUrl = $"rtsp://{feed.Username}:{feed.Password}@{feed.IPAddress}:{feed.Port}/Streaming/Channels/{feed.CameraNumber}01";
var media = new Media(_libVLC, rtspUrl, FromType.FromLocation);
var videoView = new LibVLCSharp.WPF.VideoView
{
MediaPlayer = mediaPlayer,
Margin = new Thickness(5)
};
videoView.Loaded += (_, __) => mediaPlayer.Play(media);
videoView.Unloaded += (_, __) =>
{
mediaPlayer.Stop();
mediaPlayer.Dispose();
media.Dispose();
};
VideoGrid.Children.Add(videoView);
}
}
}
}