-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathVideoView.cs
More file actions
88 lines (72 loc) · 2.07 KB
/
VideoView.cs
File metadata and controls
88 lines (72 loc) · 2.07 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
using LibVLCSharp.Shared;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
namespace RoleplayingVoiceCore {
internal class VideoView : IVideoView, IDisposable, ISupportInitialize {
public VideoView() {
}
MediaPlayer? _mp;
/// <summary>
/// The MediaPlayer attached to this view (or null)
/// </summary>
public MediaPlayer? MediaPlayer {
get => _mp;
set {
if (ReferenceEquals(_mp, value)) {
return;
}
Detach();
_mp = value;
Attach();
}
}
/// <summary>
/// This currently does not do anything
/// </summary>
void ISupportInitialize.BeginInit() {
}
/// <summary>
/// This attaches the mediaplayer to the view (if any)
/// </summary>
void ISupportInitialize.EndInit() {
if (IsInDesignMode)
return;
Attach();
}
bool IsInDesignMode {
get {
return false;
}
}
void Detach() {
if (_mp == null || _mp.NativeReference == IntPtr.Zero)
return;
_mp.Hwnd = IntPtr.Zero;
}
void Attach() {
if (_mp == null || _mp.NativeReference == IntPtr.Zero)
return;
_mp.Hwnd = Process.GetCurrentProcess().Handle;
}
bool disposedValue;
public void Dispose(bool disposing) {
if (!disposedValue) {
if (disposing) {
if (MediaPlayer != null && MediaPlayer.NativeReference != IntPtr.Zero) {
MediaPlayer.Hwnd = IntPtr.Zero;
}
}
disposedValue = true;
}
}
public void Dispose() {
Dispose(true);
}
}
}