use of org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDOutput in project malp by gateship-one.
the class MPDResponseParser method parseMPDOutputs.
/**
* Private parsing method for MPDs output lists.
*
* @return A list of MPDOutput objects with name,active,id values if successful. Otherwise empty list.
* @throws MPDException if an error from MPD was received during reading
*/
static List<MPDOutput> parseMPDOutputs(final MPDConnection connection) throws MPDException {
ArrayList<MPDOutput> outputList = new ArrayList<>();
// Parse outputs
String outputName = null;
boolean outputActive = false;
int outputId = -1;
if (!connection.isConnected()) {
return null;
}
/* Response line from MPD */
String response = connection.readLine();
while (response != null && !response.startsWith("OK")) {
if (response.startsWith(MPDResponses.MPD_OUTPUT_ID)) {
if (null != outputName) {
MPDOutput tempOutput = new MPDOutput(outputName, outputActive, outputId);
outputList.add(tempOutput);
}
outputId = Integer.valueOf(response.substring(MPDResponses.MPD_OUTPUT_ID.length()));
} else if (response.startsWith(MPDResponses.MPD_OUTPUT_NAME)) {
outputName = response.substring(MPDResponses.MPD_OUTPUT_NAME.length());
} else if (response.startsWith(MPDResponses.MPD_OUTPUT_ACTIVE)) {
String activeRespsonse = response.substring(MPDResponses.MPD_OUTPUT_ACTIVE.length());
outputActive = activeRespsonse.equals("1");
}
response = connection.readLine();
}
// Add remaining output to list
if (null != outputName) {
MPDOutput tempOutput = new MPDOutput(outputName, outputActive, outputId);
outputList.add(tempOutput);
}
return outputList;
}
Aggregations