winform-obs
winform-obs
安裝 OBS軟體 目前使用版本27.0.1
為本機OBS安裝 websocket插件,這樣WinForm才有辦法連接發指令。obs-websocket API文件
開啟obs設定port位及密碼
Windows Forms App(.NET Framework 4.6.1)
建立WebView
obs-websocket
webView1.Url = "https://google.com.tw";
EO.Base.Runtime.EnableEOWP = true;
_obs = new OBSWebsocket();
_obs.Connected += onConnect;
_obs.Connect("ws://127.0.0.1:4444", "123456");
private void onConnect(object sender, EventArgs e)
{
//更換影片放置資料夾(目前測試無法更換...)
_obs.SetRecordingFolder("D:\\git\\VisualStudio\\WebViewTest\\WebViewTest\\video");
string profile = _obs.GetCurrentProfile();
OBSScene scene = _obs.GetCurrentScene();
this.isConnect = true;
}
//對webview註冊自定義function
this.webView1.RegisterJSExtensionFunction("demoAbout", new JSExtInvokeHandler(WebView_JSDemoAbout));
window['demoAbout']("start_record");
WinForm接收通知後開始/停止錄影
void WebView_JSDemoAbout(object sender, JSExtInvokeArgs e)
{
if (this.isConnect == false)
{
Console.WriteLine("尚未連線");
}
string command = e.Arguments[0] as string;
if (command == "start_record")
{
_obs.StartRecording();
}
else
{
_obs.StopRecording();
//等待5秒存檔,並上傳FTP
wait(5000);
this.UploadFtpFile("Client\\Test\\Ray", "D:\\git\\VisualStudio\\WebViewTest\\WebViewTest\\video\\aaa.ts");
}
}