/** * 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; }
/** * Media API - Stops and unloads the current playing media * * @param callback */ public void mediaStop(ChromecastSessionCallback callback) { chromecastMediaController.stop(mApiClient, callback); }
/** * Media API - Sets the muted state on the current playing media NOT THE CHROMECAST DIRECTLY * * @param muted * @param callback */ public void mediaSetMuted(boolean muted, ChromecastSessionCallback callback) { chromecastMediaController.setMuted(muted, mApiClient, callback); }
/** * Media API - Sets the volume on the current playing media object NOT ON THE CHROMECAST DIRECTLY * * @param level * @param callback */ public void mediaSetVolume(double level, ChromecastSessionCallback callback) { chromecastMediaController.setVolume(level, mApiClient, callback); }
/** * Media API - Seeks the current playing media * * @param seekPosition - Seconds to seek to * @param resumeState - Resume state once seeking is complete: PLAYBACK_PAUSE or PLAYBACK_START * @param callback */ public void mediaSeek(long seekPosition, String resumeState, ChromecastSessionCallback callback) { chromecastMediaController.seek(seekPosition, resumeState, mApiClient, callback); }
/** * Media API - Calls pause on the current media * * @param callback */ public void mediaPause(ChromecastSessionCallback callback) { chromecastMediaController.pause(mApiClient, callback); }