private void process_Exited(object sender, EventArgs e) { int exitCode = currentProcess.ExitCode; currentProcess.Dispose(); currentProcess = null; currentPipe.Dispose(); currentPipe = null; switch (exitCode) { case 3: // CODE_LAUNCH_FAIL if (FormMessage.Error("Video Playback Error", "Error launching video player, this may be caused by missing Windows Media Player. Do you want to open the video in your browser?", FormMessage.Yes, FormMessage.No)) { BrowserUtils.OpenExternalBrowser(lastUrl); } break; case 4: // CODE_MEDIA_ERROR if (FormMessage.Error("Video Playback Error", "The video could not be loaded, most likely due to unknown format. Do you want to open the video in your browser?", FormMessage.Yes, FormMessage.No)) { BrowserUtils.OpenExternalBrowser(lastUrl); } break; } owner.InvokeAsyncSafe(TriggerProcessExitEventUnsafe); }
private void currentPipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e) { owner.InvokeSafe(() => { switch (e.Key) { case "vol": if (int.TryParse(e.Data, out int volume) && volume != Program.UserConfig.VideoPlayerVolume) { Program.UserConfig.VideoPlayerVolume = volume; Program.UserConfig.Save(); } break; case "download": TwitterUtils.DownloadVideo(lastUrl, lastUsername); break; case "rip": currentPipe.Dispose(); currentPipe = null; currentProcess.Dispose(); currentProcess = null; isClosing = false; TriggerProcessExitEventUnsafe(); break; } }); }
public Instance(Process process, DuplexPipe.Server pipe, string url, string username) { this.Process = process; this.Pipe = pipe; this.Url = url; this.Username = username; }
public Instance(Process process, DuplexPipe.Server pipe, string videoUrl, string tweetUrl, string username) { this.Process = process; this.Pipe = pipe; this.VideoUrl = videoUrl; this.TweetUrl = tweetUrl; this.Username = username; }
private void Destroy() { if (currentProcess != null) { try{ currentProcess.Kill(); }catch { // kill me instead then } currentProcess.Dispose(); currentProcess = null; currentPipe.Dispose(); currentPipe = null; TriggerProcessExitEventUnsafe(); } }
public void Launch(string url, string username) { if (Running) { Destroy(); isClosing = false; } try{ DuplexPipe.Server pipe = DuplexPipe.CreateServer(); pipe.DataIn += pipe_DataIn; Process process; if ((process = Process.Start(new ProcessStartInfo { FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"), Arguments = $"{owner.Handle} {(int)Math.Floor(100F * owner.GetDPIScale())} {Config.VideoPlayerVolume} \"{url}\" \"{pipe.GenerateToken()}\"", UseShellExecute = false, RedirectStandardOutput = true })) != null) { currentInstance = new Instance(process, pipe, url, username); process.EnableRaisingEvents = true; process.Exited += process_Exited; process.BeginOutputReadLine(); process.OutputDataReceived += process_OutputDataReceived; pipe.DisposeToken(); } else { pipe.DataIn -= pipe_DataIn; pipe.Dispose(); } }catch (Exception e) { Program.Reporter.HandleException("Video Playback Error", "Error launching video player.", true, e); } }
public void Launch(string url, string username) { if (Running) { Destroy(); isClosing = false; } lastUrl = url; lastUsername = username; try{ currentPipe = DuplexPipe.CreateServer(); currentPipe.DataIn += currentPipe_DataIn; if ((currentProcess = Process.Start(new ProcessStartInfo { FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"), Arguments = $"{owner.Handle} {Program.UserConfig.VideoPlayerVolume} \"{url}\" \"{currentPipe.GenerateToken()}\"", UseShellExecute = false, RedirectStandardOutput = true })) != null) { currentProcess.EnableRaisingEvents = true; currentProcess.Exited += process_Exited; #if DEBUG currentProcess.BeginOutputReadLine(); currentProcess.OutputDataReceived += (sender, args) => Debug.WriteLine("VideoPlayer: " + args.Data); #endif } currentPipe.DisposeToken(); }catch (Exception e) { Program.Reporter.HandleException("Video Playback Error", "Error launching video player.", true, e); } }