-
Notifications
You must be signed in to change notification settings - Fork 70
/
OBS.cs
115 lines (99 loc) · 2.36 KB
/
OBS.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
using OBS.WebSocket.NET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PowerPointToOBSSceneSwitcher
{
public class ObsLocal : IDisposable
{
private bool _DisposedValue;
private ObsWebSocket _OBS;
private List<string> validScenes;
private string defaultScene;
public ObsLocal() { }
public Task Connect()
{
_OBS = new ObsWebSocket();
_OBS.Connect($"ws://127.0.0.1:4444", "");
return Task.CompletedTask;
}
public string DefaultScene
{
get { return defaultScene; }
set
{
if (validScenes.Contains(value))
{
defaultScene = value;
}
else
{
Console.WriteLine($"Scene named {value} does not exist and cannot be set as default");
}
}
}
public bool ChangeScene(string scene)
{
if (!validScenes.Contains(scene))
{
Console.WriteLine($"Scene named {scene} does not exist");
if (String.IsNullOrEmpty(defaultScene))
{
Console.WriteLine("No default scene has been set!");
return false;
}
scene = defaultScene;
}
_OBS.Api.SetCurrentScene(scene);
return true;
}
public void GetScenes()
{
var allScene = _OBS.Api.GetSceneList();
var list = allScene.Scenes.Select(s => s.Name).ToList();
Console.WriteLine("Valid Scenes:");
foreach(var l in list)
{
Console.WriteLine(l);
}
validScenes = list;
}
public bool StartRecording()
{
try { _OBS.Api.StartRecording(); }
catch { /* Recording already started */ }
return true;
}
public bool StopRecording()
{
try { _OBS.Api.StopRecording(); }
catch { /* Recording already stopped */ }
return true;
}
protected virtual void Dispose(bool disposing)
{
if (!_DisposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
_OBS.Disconnect();
_OBS = null;
_DisposedValue = true;
}
}
~ObsLocal()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}