Search in sources :

Example 6 with MPDOutput

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;
}
Also used : MPDOutput(org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDOutput) ArrayList(java.util.ArrayList)

Aggregations

MPDOutput (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDOutput)6 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 SubMenu (android.view.SubMenu)1 View (android.view.View)1 PopupMenu (android.widget.PopupMenu)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OutputListItem (org.gateshipone.malp.application.listviewitems.OutputListItem)1 MPDResponseAlbumList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseAlbumList)1 MPDResponseArtistList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseArtistList)1 MPDResponseFileList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseFileList)1 MPDResponseHandler (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseHandler)1 MPDResponseOutputList (org.gateshipone.malp.mpdservice.handlers.responsehandler.MPDResponseOutputList)1 MPDCapabilities (org.gateshipone.malp.mpdservice.mpdprotocol.MPDCapabilities)1 MPDCommands (org.gateshipone.malp.mpdservice.mpdprotocol.MPDCommands)1 MPDException (org.gateshipone.malp.mpdservice.mpdprotocol.MPDException)1 MPDAlbum (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDAlbum)1 MPDArtist (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDArtist)1 MPDCurrentStatus (org.gateshipone.malp.mpdservice.mpdprotocol.mpdobjects.MPDCurrentStatus)1