public MpdStatus Status()
{
MpdResponse response = this.getConnection().Exec("status");
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
int volume = -1;
bool repeat = false;
bool random = false;
int playlist = -1;
int playlistLength = -1;
int playlistQueue = -1;
int xFade = -1;
MpdState state = MpdState.Unknown;
int song = -1;
int songId = -1;
int timeElapsed = -1;
int timeTotal = -1;
int bitrate = -1;
int audioSampleRate = -1;
int audioBits = -1;
int audioChannels = -1;
int updatingDb = -1;
string error = null;
foreach (KeyValuePair<string, string> line in response) {
if ((line.Key != null) && (line.Value != null))
switch (line.Key) {
case "volume": {
int tryValue;
if (int.TryParse(line.Value, out tryValue)) {
volume = tryValue;
if (volume < 0)
volume = 0;
if (volume > 100)
volume = 100;
}
}
break;
case "repeat":
repeat = (line.Value != null) && (line.Value.Equals("1"));
break;
case "random":
random = (line.Value != null) && (line.Value.Equals("1"));
break;
case "playlist": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
playlist = tryValue;
}
break;
case "playlistlength": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
playlistLength = tryValue;
}
break;
case "playlistqueue": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
playlistQueue = tryValue;
}
break;
case "xfade": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
xFade = tryValue;
}
break;
case "state":
switch (line.Value) {
case "play":
state = MpdState.Play;
break;
case "pause":
state = MpdState.Pause;
break;
case "stop":
state = MpdState.Stop;
break;
}
break;
case "song": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
song = tryValue;
}
break;
case "songid": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
songId = tryValue;
}
break;
case "time":
int index = line.Value.IndexOf(':');
if (index >= 0) {
int tryValue;
if (int.TryParse(line.Value.Substring(0, index), out tryValue))
timeElapsed = tryValue;
if (int.TryParse(line.Value.Substring(index + 1), out tryValue))
timeTotal = tryValue;
}
break;
case "bitrate": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
bitrate = tryValue;
}
break;
case "audio":
Match match = STATUS_AUDIO_REGEX.Match(line.Value);
if (match.Success) {
int tryValue;
if (int.TryParse(match.Result("$sampleRate"), out tryValue))
audioSampleRate = tryValue;
if (int.TryParse(match.Result("$bits"), out tryValue))
audioBits = tryValue;
if (int.TryParse(match.Result("$channels"), out tryValue))
audioChannels = tryValue;
}
break;
case "updating_db": {
int tryValue;
if (int.TryParse(line.Value, out tryValue))
updatingDb = tryValue;
}
break;
case "error":
error = line.Value;
break;
}
}
return new MpdStatus(
volume,
repeat,
random,
playlist,
playlistLength,
xFade,
state,
song,
songId,
timeElapsed,
timeTotal,
bitrate,
audioSampleRate,
audioBits,
audioChannels,
updatingDb,
error
);
}