public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { newBrowser = null; if (targetUrl.StartsWith("https://open.spotify.com/track/") || targetUrl.StartsWith("https://play.spotify.com/track/")) { Spotify spotify = new Spotify(targetUrl, _instance); return(true); } else if (Threema_Desktop_Client.Properties.Settings.Default.defaultbrowser) { System.Diagnostics.Process.Start(targetUrl); return(true); } else { _instance.addTabUrl(targetUrl); _instance.Invoke(new Action(() => { if (_instance.splitContainer1.SplitterDistance == _instance.splitContainer1.Width) { _instance.splitContainer1.SplitterDistance = _instance.splitContainer1.Width - 200; } else { return; } })); return(true); } }
public Spotify(String uri, TDC tdc) { _instance = tdc; //var runningProcessByName = Process.GetProcessesByName("Spotify"); /*if (runningProcessByName.Length == 0) * { * Process P = Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Spotify/spotify.exe"); * while (!P.Responding) * { * Console.WriteLine("spotify not responding!"); * } * }*/ String[] split = uri.Split('?'); if (uri.StartsWith("https://")) { //TDC tdc = new TDC(); //prepare(); _spotify = new SpotifyLocalAPI(); if (!SpotifyLocalAPI.IsSpotifyRunning()) { SpotifyLocalAPI.RunSpotify(); } if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning()) { SpotifyLocalAPI.RunSpotifyWebHelper(); } if (!_spotify.Connect()) { return; } split[0] = "spotify:track:" + split[0].Substring(31, split[0].Length - 31); _spotify.PlayURL(split[0]); Thread.Sleep(100); _spotify = new SpotifyLocalAPI(); if (!SpotifyLocalAPI.IsSpotifyRunning()) { SpotifyLocalAPI.RunSpotify(); } if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning()) { SpotifyLocalAPI.RunSpotifyWebHelper(); } if (!_spotify.Connect()) { return; } StatusResponse _response = _spotify.GetStatus(); Track track = _response.Track; Console.WriteLine(track.TrackResource.Name); _instance.Invoke(new Action(() => { _instance.trayIcon.Visible = true; _instance.trayIcon.BalloonTipTitle = "Now playing on Spotify:"; _instance.trayIcon.BalloonTipIcon = ToolTipIcon.Info; _instance.trayIcon.BalloonTipText = track.TrackResource.Name + " by " + track.ArtistResource.Name; _instance.trayIcon.ShowBalloonTip(1000); })); } else if (uri.StartsWith("spotify:track:")) { _spotify.PlayURL(uri); } }