/** * Mutes the receiver * * @param muted * @param callback */ public void setMute(boolean muted, ChromecastSessionCallback callback) { try { Cast.CastApi.setMute(mApiClient, muted); callback.onSuccess(); } catch (Exception e) { e.printStackTrace(); callback.onError(e.getMessage()); } }
/** * Sets the receiver volume level * * @param volume * @param callback */ public void setVolume(double volume, ChromecastSessionCallback callback) { try { Cast.CastApi.setVolume(mApiClient, volume); callback.onSuccess(); } catch (Exception e) { e.printStackTrace(); callback.onError(e.getMessage()); } }
/** * Kills a session and it's underlying media player * * @param callback */ public void kill(final ChromecastSessionCallback callback) { // this.mRemoteMediaPlayer.stop(mApiClient).setResultCallback(new // ResultCallback<RemoteMediaPlayer.MediaChannelResult>() { // @Override // public void onResult(MediaChannelResult result) { // try { // Cast.CastApi.stopApplication(mApiClient); // mApiClient.disconnect(); // } catch(Exception e) { // // } // // callback.onSuccess(); // } // }); try { Cast.CastApi.stopApplication(mApiClient); mApiClient.disconnect(); } catch (Exception e) { } callback.onSuccess(); // Cast.CastApi.stopApplication(mApiClient); }
/** * Loads media over the media API * * @param contentId - The URL of the content * @param contentType - The MIME type of the content * @param duration - The length of the video (if known) * @param streamType * @param autoPlay - Whether or not to start the video playing or not * @param currentTime - Where in the video to begin playing from * @param callback * @return */ public boolean loadMedia( String contentId, String contentType, long duration, String streamType, boolean autoPlay, double currentTime, final ChromecastSessionCallback callback) { try { MediaInfo mediaInfo = chromecastMediaController.createLoadUrlRequest( contentId, contentType, duration, streamType); mRemoteMediaPlayer .load(mApiClient, mediaInfo, autoPlay, (long) (currentTime * 1000)) .setResultCallback( new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() { @Override public void onResult(MediaChannelResult result) { if (result.getStatus().isSuccess()) { System.out.println("Media loaded successfully"); callback.onSuccess(ChromecastSession.this.createMediaObject()); } else { callback.onError("session_error"); } } }); } catch (IllegalStateException e) { e.printStackTrace(); System.out.println("Problem occurred with media during loading"); callback.onError("session_error"); return false; } catch (Exception e) { e.printStackTrace(); callback.onError("session_error"); System.out.println("Problem opening media during loading"); return false; } return true; }
/** * Sends a message to a specified namespace * * @param namespace * @param message * @param callback */ public void sendMessage( String namespace, String message, final ChromecastSessionCallback callback) { try { Cast.CastApi.sendMessage(mApiClient, namespace, message) .setResultCallback( new ResultCallback<Status>() { @Override public void onResult(Status result) { if (!result.isSuccess()) { callback.onSuccess(); } else { callback.onError(result.toString()); } } }); } catch (Exception e) { callback.onError(e.getMessage()); } }