Exemple #1
0
 // Next task after successful connection
 private void MPDClient_NextTaskToPorform(object sender, NextEventArgs e)
 {
     this.SendCommand(e.Command, e.Attributes);
 }
Exemple #2
0
 // 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);
 }
Exemple #3
0
        /// <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();
            }
        }