private void joinSession(RouteInfo routeInfo) { ChromecastSession sessionJoinAttempt = new ChromecastSession(routeInfo, this.cordova, this, this); sessionJoinAttempt.join( this.appId, this.lastSessionId, new ChromecastSessionCallback() { @Override void onSuccess(Object object) { if (Chromecast.this.currentSession == null) { try { Chromecast.this.currentSession = (ChromecastSession) object; Chromecast.this.setLastSessionId(Chromecast.this.currentSession.getSessionId()); sendJavascript( "chrome.cast._.sessionJoined(" + Chromecast.this.currentSession.createSessionObject().toString() + ");"); } catch (Exception e) { log("wut.... " + e.getMessage() + e.getStackTrace()); } } } @Override void onError(String reason) { log("sessionJoinAttempt error " + reason); } }); }
/** * Pause on the current media in the current session * * @param callbackContext * @return */ public boolean mediaPause(CallbackContext callbackContext) { if (currentSession != null) { currentSession.mediaPause(genericCallback(callbackContext)); } else { callbackContext.error("session_error"); } return true; }
/** * Set the muted on the media * * @param muted * @param callbackContext * @return */ public boolean setMediaMuted(Boolean muted, CallbackContext callbackContext) { if (currentSession != null) { currentSession.mediaSetMuted(muted, genericCallback(callbackContext)); } else { callbackContext.error("session_error"); } return true; }
/** * Set the volume on the media * * @param level * @param callbackContext * @return */ public boolean setMediaVolume(Double level, CallbackContext callbackContext) { if (currentSession != null) { currentSession.mediaSetVolume(level, genericCallback(callbackContext)); } else { callbackContext.error("session_error"); } return true; }
/** * Seeks the current media in the current session * * @param seekTime * @param resumeState * @param callbackContext * @return */ public boolean mediaSeek(Integer seekTime, String resumeState, CallbackContext callbackContext) { if (currentSession != null) { currentSession.mediaSeek( seekTime.longValue() * 1000, resumeState, genericCallback(callbackContext)); } else { callbackContext.error("session_error"); } return true; }
@Override public void onMessage(ChromecastSession session, String namespace, String message) { sendJavascript( "chrome.cast._.onMessage('" + session.getSessionId() + "', '" + namespace + "', '" + message + "')"); }