forked from Geektoolkit/Dynaframe3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoPlayer.cs
166 lines (147 loc) · 5.94 KB
/
VideoPlayer.cs
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
using Avalonia.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Dynaframe3
{
static class VideoPlayer
{
static public bool IsPlaying;
static private Process videoProcess; // handle to the video Player
static public Window MainWindowHandle;
static public Panel MainPanelHandle;
public static void PlayVideo(string VideoPath)
{
IsPlaying = true;
Logger.LogComment("Entering PlayVideoFile with Path: " + VideoPath);
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.WindowStyle = ProcessWindowStyle.Maximized;
// TODO: Parameterize omxplayer settings
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Logger.LogComment("Linux Detected, setting up OMX Player");
pInfo.FileName = "omxplayer";
Logger.LogComment("Setting up Appsettings...");
pInfo.Arguments = AppSettings.Default.OXMOrientnation + " --aspect-mode " + AppSettings.Default.VideoStretch + " ";
// Append volume command argument
if (!AppSettings.Default.VideoVolume)
{
pInfo.Arguments += "--vol -6000 ";
}
pInfo.Arguments += "\"" + VideoPath + "\"";
Logger.LogComment("DF Playing: " + VideoPath);
Logger.LogComment("OMXPLayer args: " + pInfo.Arguments);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
pInfo.UseShellExecute = true;
pInfo.FileName = "wmplayer.exe";
pInfo.Arguments = "\"" + VideoPath + "\"";
pInfo.Arguments += " /fullscreen";
Logger.LogComment("Looking for media in: " + pInfo.Arguments);
}
videoProcess = new Process();
videoProcess.StartInfo = pInfo;
Logger.LogComment("PlayVideoFile: Starting player...");
videoProcess.Start();
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
MainWindowHandle.Opacity = 0;
});
// Give video player time to start, then fade out to reveal it...
System.Threading.Thread.Sleep(1100);
Logger.LogComment("PlayVideoFile: Fading Foreground to reveal video player.");
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
MainWindowHandle.Opacity = 0;
});
}
/// <summary>
/// Returns true if the video is playing, false if it isn't...
/// </summary>
/// <returns></returns>
public static bool CheckStatus(bool ForceTransition)
{
if ((videoProcess == null) || (videoProcess.HasExited))
{
IsPlaying = false;
KillVideoPlayer();
Logger.LogComment("VideoPlayer CheckStatus returning false..: Video has exited!");
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
MainPanelHandle.Opacity = 1;
MainWindowHandle.Opacity = 1;
});
return false;
}
else if((AppSettings.Default.PlaybackFullVideo == false) && (ForceTransition))
{
// We should interupt the video...check status gets called at the slide transition time.
Logger.LogComment("VideoPlayer is closing playing video to transition to images..");
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
MainPanelHandle.Opacity = 1;
MainWindowHandle.Opacity = 1;
});
VideoPlayer.KillVideoPlayer();
return true;
}
else
{
return true;
}
}
public static void KillVideoPlayer()
{
Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
MainPanelHandle.Opacity = 1;
MainWindowHandle.Opacity = 1;
});
Logger.LogComment("KillVideoPlayer - Entering Method.");
try
{
if (videoProcess != null)
{
try
{
videoProcess.CloseMainWindow();
videoProcess = null;
}
catch (InvalidOperationException)
{
// expected if the process isn't there.
}
catch (Exception exc)
{
Debug.WriteLine("Tried and failed to kill video process..." + exc.ToString());
Logger.LogComment("Tried and failed to kill video process. Exception: " + exc.ToString());
}
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// OMXPlayer processes can be a bit tricky. to kill them we use
// killall - 9 omxplayer.bin
// -q quiets this down in case omxplayer isn't running
Helpers.RunProcess("killall", "-q -9 omxplayer.bin");
videoProcess = null;
}
else
{
videoProcess.Close();
videoProcess.Dispose();
videoProcess = null;
}
}
catch (Exception)
{
// Swallow. This may no longer be there depending on what kills it (OMX player will exit if the video
// completes for instance
}
}
}
}