-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFullscreenWindow.xaml.cs
More file actions
279 lines (230 loc) · 8.92 KB
/
FullscreenWindow.xaml.cs
File metadata and controls
279 lines (230 loc) · 8.92 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Graphics;
using System.Threading.Tasks;
using System.Threading;
using Windows.Storage;
using AppUIBasics.ControlPages;
using static System.Net.Mime.MediaTypeNames;
using Windows.Media.Core;
using Windows.Media.Playback;
using Windows.Media;
using Windows.UI.ViewManagement;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.Graphics.Display;
using WinRT.Interop;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ImageRate.Assets
{
public sealed partial class FullscreenWindow : Window
{
bool img_1_active = false;
PeriodicTimer autoplay_timer = null;
MainWindow fromWindow;
public FullscreenWindow(MainWindow fromWindow)
{
InitializeComponent();
AppWindow.SetIcon("Assets/ImageRate_Icon.ico");
this.fromWindow = fromWindow;
initMonitorFlyout();
//ProjectionManager.
VideoView.SetMediaPlayer(new MediaPlayer());
VideoView.MediaPlayer.Volume = 0;
fromWindow.mediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
fromWindow.mediaPlayer.PlaybackSession.PositionChanged += PlaybackSession_PositionChanged;
Closed += (o,w) => {
autoplay_timer?.Dispose();
fromWindow.mediaPlayer.PlaybackSession.PlaybackStateChanged -= PlaybackSession_PlaybackStateChanged;
fromWindow.mediaPlayer.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
};
}
private void initMonitorFlyout()
{
var monitors = MonitorHelper.GetAllMonitorsInfo();
for (int i = 0; i < monitors.Count; i++)
{
var monitor = monitors[i];
var menuItem = new ToggleMenuFlyoutItem();
menuItem.Text = monitor.DeviceName;
MonitorSubmenu.Items.Add(menuItem);
menuItem.Click += (s, e) => {
AppWindow.Move(new PointInt32(monitor.Monitor.Left, monitor.Monitor.Top));
AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
foreach(var item in MonitorSubmenu.Items)
{
(item as ToggleMenuFlyoutItem).IsChecked = false;
}
menuItem.IsChecked = true;
};
if (i == monitors.Count - 1)
{
menuItem.IsChecked = true;
AppWindow.Move(new PointInt32(monitor.Monitor.Left, monitor.Monitor.Top));
AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
}
}
}
/*{
var areas = DisplayArea.FindAll();
for (int i = 0; i < areas.Count; i++)
{
DisplayArea item = areas[i];
MenuFlyoutItem menuItem = new MenuFlyoutItem();
menuItem.Text = $"Monitor {i + 1}";
if (item.IsPrimary) menuItem.Text += " (primary)";
MonitorSubmenu.Items.Add(menuItem);
menuItem.Click += (s, e) => {
AppWindow.Move(new PointInt32(item.OuterBounds.X, item.OuterBounds.Y));
AppWindow.SetPresenter(AppWindowPresenterKind.FullScreen);
};
}
Screen.AllScreens
}*/
// Sync the playback state of mediaPlayer2 with mediaPlayer1
private void PlaybackSession_PlaybackStateChanged(MediaPlaybackSession sender, object args)
{
var dispatcherQueue = DispatcherQueue.TryEnqueue(() =>
{
switch (sender.PlaybackState)
{
case MediaPlaybackState.Playing:
VideoView.MediaPlayer.Play();
break;
case MediaPlaybackState.Paused:
VideoView.MediaPlayer.Pause();
break;
}
});
}
// Sync the playback position of mediaPlayer2 with mediaPlayer1
private void PlaybackSession_PositionChanged(MediaPlaybackSession sender, object args)
{
var dispatcherQueue = DispatcherQueue.TryEnqueue(() =>
{
if (VideoView.MediaPlayer != null &&
Math.Abs((sender.Position - VideoView.MediaPlayer.PlaybackSession.Position).TotalMilliseconds) > 50)
{
VideoView.MediaPlayer.PlaybackSession.Position = sender.Position;
}
});
}
private void FullscreenWindow_KeyDown(object sender, KeyRoutedEventArgs args)
{
if (args.Key == Windows.System.VirtualKey.Left)
{
fromWindow.loadPrevImg();
}
if (args.Key == Windows.System.VirtualKey.Right)
{
fromWindow.loadNextImg();
}
if (args.Key == Windows.System.VirtualKey.Escape)
{
Close();
}
if (args.Key == Windows.System.VirtualKey.Space)
{
toggleAutoplay();
}
}
public void SetCurrentImagePath(ImageItem item)
{
var itemPath = new Uri(item.Path, UriKind.Absolute);
if (item.File.ContentType.StartsWith("video/"))
{
VideoView.MediaPlayer.Source = MediaSource.CreateFromUri(itemPath);
VideoView.Opacity = 1;
ImageView1.Opacity = 0;
ImageView2.Opacity = 0;
}
else
{
VideoView.Source = null;
VideoView.Opacity = 0;
var ToImageView = img_1_active ? ImageView2 : ImageView1;
var FromImageView = img_1_active ? ImageView1 : ImageView2;
img_1_active = !img_1_active;
ToImageView.Source = new BitmapImage(itemPath);
ToImageView.Opacity = 1;
FromImageView.Opacity = 0;
}
}
public void toggleAutoplay()
{
if (autoplay_timer != null)
{
autoplay_timer.Dispose();
autoplay_timer = null;
AutoplayToogle.IsChecked = false;
}
else
{
sheduleAutoplayTimer();
AutoplayToogle.IsChecked = true;
}
}
private async void changeDelay()
{
ContentDialog dialog = new ContentDialog();
dialog.XamlRoot = Content.XamlRoot;
dialog.Title = "Set image duration (in seconds)";
dialog.CloseButtonText = "OK";
dialog.DefaultButton = ContentDialogButton.Close;
var content = new DelaySettingsDialogContent(getDelay());
dialog.Content = content;
await dialog.ShowAsync();
SettingsHelper.set("dia_delay", content.getDuration());
if (autoplay_timer != null)
{
autoplay_timer.Dispose();
autoplay_timer = null;
toggleAutoplay();
}
}
private int getDelay()
{
return SettingsHelper.getIntOrDefault("dia_delay", 6);
}
private async Task sheduleAutoplayTimer()
{
fromWindow.loadNextImg();
autoplay_timer = new PeriodicTimer(TimeSpan.FromSeconds(getDelay()));
while (await autoplay_timer.WaitForNextTickAsync())
{
if (VideoView.MediaPlayer.PlaybackSession.PlaybackState != MediaPlaybackState.Playing) fromWindow.loadNextImg();
}
}
private void MenuFlyoutItem_Close_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
ContextMenu.ShowAt(sender as UIElement, e.GetPosition(sender as UIElement));
}
private void MenuFlyoutItem_ToogleAutoplay(object sender, RoutedEventArgs e)
{
toggleAutoplay();
}
private void MenuFlyoutItem_ConfigureAutoplay(object sender, RoutedEventArgs e)
{
changeDelay();
}
}
}