// Next task after successful connection private void MPDClient_NextTaskToPorform(object sender, NextEventArgs e) { this.SendCommand(e.Command, e.Attributes); }
// If not connected, but needs to play // After successfull connection this method is being called private void mpdclient_nextEventToPorform(object sender, NextEventArgs e) { Connection.SendCommand(MPDClient.PLAY); }
/// <summary> /// Send given command and parameters to the server /// </summary> /// <param name="command">Command</param> /// <param name="attributes">Attributes</param> public void SendCommand(string command, string[] attributes = null) { if (this.IsConnected) { StringBuilder sb = new StringBuilder(command); string space = ""; if (attributes != null) { sb.Append(" \""); foreach (string attr in attributes) { sb.Append(space + attr); space = " "; } sb.Append("\""); } SocketAsyncEventArgs asyncEvent = new SocketAsyncEventArgs { RemoteEndPoint = new DnsEndPoint(this.Server, this.Port) }; byte[] buffer = Encoding.UTF8.GetBytes(sb.ToString() + Environment.NewLine); asyncEvent.Completed += asyncEvent_Completed; asyncEvent.SetBuffer(buffer, 0, buffer.Length); connection.SendAsync(asyncEvent); } else { this.nextArgs = new NextEventArgs(command, attributes); this.NextTaskToPorform += MPDClient_NextTaskToPorform; this.Connect(); } }