Search in sources :

Example 1 with MediaStatus

use of su.litvak.chromecast.api.v2.MediaStatus in project UniversalMediaServer by UniversalMediaServer.

the class ChromecastPlayer method startPoll.

public void startPoll() {
    Runnable r = new Runnable() {

        @Override
        public void run() {
            for (; ; ) {
                try {
                    Thread.sleep(1000);
                    Status s1 = api.getStatus();
                    if (s1 == null || !s1.isAppRunning(MediaPlayer)) {
                        continue;
                    }
                    MediaStatus status = api.getMediaStatus();
                    if (status == null) {
                        continue;
                    }
                    state.playback = translateState(status.playerState);
                    Media m = status.media;
                    if (m != null) {
                        if (m.url != null) {
                            state.uri = status.media.url;
                        }
                        if (m.duration != null) {
                            state.duration = StringUtil.convertTimeToString(status.media.duration, "%02d:%02d:%02.0f");
                        }
                    }
                    state.position = StringUtil.convertTimeToString(status.currentTime, "%02d:%02d:%02.0f");
                    if (status.volume != null) {
                        state.volume = status.volume.level.intValue();
                        state.mute = status.volume.muted;
                    }
                    alert();
                } catch (InterruptedException | IOException e) {
                    LOGGER.debug("Bad chromecast mediastate " + e);
                }
            }
        }
    };
    poller = new Thread(r);
    poller.start();
}
Also used : MediaStatus(su.litvak.chromecast.api.v2.MediaStatus) Status(su.litvak.chromecast.api.v2.Status) Media(su.litvak.chromecast.api.v2.Media) IOException(java.io.IOException) MediaStatus(su.litvak.chromecast.api.v2.MediaStatus)

Aggregations

IOException (java.io.IOException)1 Media (su.litvak.chromecast.api.v2.Media)1 MediaStatus (su.litvak.chromecast.api.v2.MediaStatus)1 Status (su.litvak.chromecast.api.v2.Status)1