public bool startProducer(IVoiceTarget targetManager) { if (OperatingSystem.IsWindows()) { informChannel(Ts3Client, "Windows Version"); Task.Factory.StartNew(() => { //Starting a Task bc WaitForConnection blocks execution var stream = new NamedPipeServerStream(spotifyPluginConfig.getPipeName(), PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.None); stream.WaitForConnection(); producer = new SpotifyStreamAudioProducer(stream, player, rootConf); }); } else { informChannel(Ts3Client, "Linux Version"); var fifo = "/tmp/" + spotifyPluginConfig.getPipeName(); if (!File.Exists(fifo)) { var output = ("mkfifo " + fifo).Bash(); Console.WriteLine(output); } FileStream s = new FileStream("/tmp/" + spotifyPluginConfig.getPipeName(), FileMode.Open); producer = new SpotifyStreamAudioProducer(s, player, rootConf); } spotifyInstance = new SpotifyInstance(spotifyPluginConfig, activeSpotifyAccount); spotifyInstance.startProcess(); int tries = 0; while (!spotifyInstance.connected && tries++ < 4) { Thread.Sleep(500); } if (!spotifyInstance.connected || spotifyInstance.hasExited()) { return(false); } targetManager.SendMode = TargetSendMode.Voice; producer.start(); return(true); }
private void stopSpotify() { lock (_lock) { if (spotifyInstance != null && !spotifyInstance.hasExited()) { spotifyInstance.stopProcess(); } producer?.Dispose(); producer = null; spotifyInstance = null; activeSpotifyControl = null; activeSpotifyAccount = null; } }
public void LoginStepFour(SpotifyAccount account, ClientCall invoker, string password) { //Start Librespot and check Password string information = ""; information += "Lets check it quickly."; Ts3Client.SendMessage(information, invoker.ClientId.Value); SpotifyInstance newInstance = new SpotifyInstance(spotifyPluginConfig, account); newInstance.useLogin(account.email, password); newInstance.startProcess(); int tries = 0; while (!newInstance.connected && tries++ < 4) { Thread.Sleep(500); } if (!newInstance.connected || newInstance.hasExited()) { Ts3Client.SendMessage("Credentials not right.", invoker.ClientId.Value); return; } SpotifyControl newControl = new SpotifyControl(spotifyPluginConfig, rootConf); newControl.logintoken(account.code, (bool success, bool tell, string accessToken, string refreshToken) => { if (success) { account.refreshToken = refreshToken; account.accessToken = accessToken; spotifyPluginConfig.accountList.Add(account); saveConfig(); Ts3Client.SendMessage("You can use Spotify now.", invoker.ClientId.Value); } else { Ts3Client.SendMessage("Something went wrong check your Auth-Token.", invoker.ClientId.Value); } }); }