mpd :: MPDConnection :: status
# Get MPD server status
fun status: nullable ServerStatus
do
if socket == null then connect
var volume: nullable Int = null
var state: nullable String = null
var elapsed: nullable Int = null
var time_at: nullable Int = null
var time_total: nullable Int = null
# get current status
socket.write("status\n")
var rep = socket.read(1024)
for l in rep.split_with("\n") do
var words = l.split_with(" ")
if words.length > 1 then
var key = words[0].to_lower
var first_space = l.chars.index_of(' ')
var rest = l.substring_from(first_space+1)
if key == "volume:" then
volume = rest.to_i
if volume == -1 then volume = null
else if key == "state:" then
state = rest
else if key == "elapsed:" then
elapsed = rest.to_i
else if key == "time:" then
var times = rest.split(":")
time_at = times[0].to_i
time_total = times[1].to_i
end
end
end
if state != null then
var status = new ServerStatus(volume, state, elapsed, time_at, time_total)
return status
else
return null
end
end
lib/mpd/mpd.nit:80,2--121,4