Search in sources :

Example 1 with PlayStateStatus

use of com.connectsdk.service.capability.MediaControl.PlayStateStatus in project butter-android by butterproject.

the class DLNAHttpServer method handleEntry.

private void handleEntry(JSONObject entry) throws JSONException {
    if (entry.has("TransportState")) {
        String transportState = entry.getString("TransportState");
        PlayStateStatus status = PlayStateStatus.convertTransportStateToPlayStateStatus(transportState);
        for (URLServiceSubscription<?> sub : subscriptions) {
            if (sub.getTarget().equalsIgnoreCase("playState")) {
                for (int j = 0; j < sub.getListeners().size(); j++) {
                    @SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(j);
                    Util.postSuccess(listener, status);
                }
            }
        }
    }
    if ((entry.has("Volume") && !entry.has("channel")) || (entry.has("Volume") && entry.getString("channel").equals("Master"))) {
        int intVolume = entry.getInt("Volume");
        float volume = (float) intVolume / 100;
        for (URLServiceSubscription<?> sub : subscriptions) {
            if (sub.getTarget().equalsIgnoreCase("volume")) {
                for (int j = 0; j < sub.getListeners().size(); j++) {
                    @SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(j);
                    Util.postSuccess(listener, volume);
                }
            }
        }
    }
    if ((entry.has("Mute") && !entry.has("channel")) || (entry.has("Mute") && entry.getString("channel").equals("Master"))) {
        String muteStatus = entry.getString("Mute");
        boolean mute;
        try {
            mute = (Integer.parseInt(muteStatus) == 1);
        } catch (NumberFormatException e) {
            mute = Boolean.parseBoolean(muteStatus);
        }
        for (URLServiceSubscription<?> sub : subscriptions) {
            if (sub.getTarget().equalsIgnoreCase("mute")) {
                for (int j = 0; j < sub.getListeners().size(); j++) {
                    @SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(j);
                    Util.postSuccess(listener, mute);
                }
            }
        }
    }
    if (entry.has("CurrentTrackMetaData")) {
        String trackMetaData = entry.getString("CurrentTrackMetaData");
        MediaInfo info = DLNAMediaInfoParser.getMediaInfo(trackMetaData);
        for (URLServiceSubscription<?> sub : subscriptions) {
            if (sub.getTarget().equalsIgnoreCase("info")) {
                for (int j = 0; j < sub.getListeners().size(); j++) {
                    @SuppressWarnings("unchecked") ResponseListener<Object> listener = (ResponseListener<Object>) sub.getListeners().get(j);
                    Util.postSuccess(listener, info);
                }
            }
        }
    }
}
Also used : MediaInfo(com.connectsdk.core.MediaInfo) PlayStateStatus(com.connectsdk.service.capability.MediaControl.PlayStateStatus) JSONObject(org.json.JSONObject) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener)

Aggregations

MediaInfo (com.connectsdk.core.MediaInfo)1 PlayStateStatus (com.connectsdk.service.capability.MediaControl.PlayStateStatus)1 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 JSONObject (org.json.JSONObject)1