-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVirtualDesktopPlaybackSettings.cs
More file actions
executable file
·131 lines (118 loc) · 4.34 KB
/
VirtualDesktopPlaybackSettings.cs
File metadata and controls
executable file
·131 lines (118 loc) · 4.34 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
using System;
using System.Reflection;
using System.Windows;
using MethodRedirect;
namespace VirtualDesktopTimecodeServer
{
public sealed class VirtualDesktopPlaybackSettings
{
public static VirtualDesktopPlaybackSettings Instance
{
get
{
return lazy.Value;
}
}
public double VideoPositionInSeconds
{
get
{
return _videoPositionInSeconds;
}
}
public string VideoPositionInSecondsString
{
get
{
return String
.Format("{0:0.000}", _videoPositionInSeconds)
.Replace(",", ".");
}
}
public bool IsPlaying
{
get
{
return _isPlaying;
}
}
public string VideoPath
{
get
{
return _videoPath;
}
set
{
_videoPath = value;
}
}
public void Update()
{
var playbackSettingsInstance = GetPlaybackSettingsInstance();
var videoPosition = (long)playbackSettingsInstance
.GetType()
.GetProperty("VideoPosition")
.GetValue(playbackSettingsInstance);
var videoPositionTimeSpan = new TimeSpan(videoPosition - videoPosition % 10000L);
_videoPositionInSeconds = videoPositionTimeSpan.TotalSeconds;
_isPlaying = (bool)playbackSettingsInstance
.GetType()
.GetProperty("IsPlaying")
.GetValue(playbackSettingsInstance);
}
private VirtualDesktopPlaybackSettings()
{
var playbackSettinsType = Type.GetType("VirtualDesktop.Engine.PlaybackSettings,Virtual Desktop");
// we have to use `1 to get the generic class type
var settingsBaseType = Type.GetType("VirtualDesktop.Core.SettingsBase`1,Virtual Desktop");
var settingsBasePlaybackSettingsType = settingsBaseType.MakeGenericType(playbackSettinsType);
_settingsBasePlaybackSettingsDefaultProperty = settingsBasePlaybackSettingsType
.GetProperty(
"Default",
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public
);
_playVideo = Application.Current.MainWindow
.GetType()
.GetMethod(
"PlayVideo",
BindingFlags.Instance | BindingFlags.Public
);
_playVideoReplacement = this
.GetType()
.GetMethod(
"PlayVideoReplacement",
BindingFlags.Instance | BindingFlags.NonPublic
);
InjectPlayVideoMethodRedirect();
}
private void PlayVideoReplacement(string path)
{
VirtualDesktopPlaybackSettings.Instance.VideoPath = path;
VirtualDesktopPlaybackSettings.Instance.PlayVideoInvoker(path);
}
public void PlayVideoInvoker(string path)
{
_playVideoMethodRedirekt.Restore();
_playVideo.Invoke(Application.Current.MainWindow, new object[] { path });
InjectPlayVideoMethodRedirect();
}
private void InjectPlayVideoMethodRedirect()
{
_playVideoMethodRedirekt = _playVideo.RedirectTo(_playVideoReplacement);
}
private object GetPlaybackSettingsInstance()
{
return _settingsBasePlaybackSettingsDefaultProperty.GetValue(null, null);
}
private PropertyInfo _settingsBasePlaybackSettingsDefaultProperty;
private double _videoPositionInSeconds = 0.0;
private bool _isPlaying = false;
private string _videoPath = String.Empty;
private MethodInfo _playVideo;
private MethodInfo _playVideoReplacement;
private MethodOperation _playVideoMethodRedirekt;
private static readonly Lazy<VirtualDesktopPlaybackSettings> lazy =
new Lazy<VirtualDesktopPlaybackSettings>(() => new VirtualDesktopPlaybackSettings());
}
}