com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult Java Examples

The following examples show how to use com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Loads a media. For this to succeed, you need to have successfully launched the application.
 *
 * @param media
 * @param autoPlay   If <code>true</code>, playback starts after load
 * @param position   Where to start the playback (only used if autoPlay is <code>true</code>).
 *                   Units is milliseconds.
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void loadMedia(MediaInfo media, boolean autoPlay, int position, JSONObject customData)
        throws TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "loadMedia: " + media);
    checkConnectivity();
    if (media == null) {
        return;
    }
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to load a video with no active media session");
        throw new NoConnectionException();
    }

    mRemoteMediaPlayer.load(mApiClient, media, autoPlay, position, customData)
            .setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_load, result.getStatus().getStatusCode());
                    }

                }
            });
}
 
Example #2
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Resumes the playback from where it was left (can be the beginning).
 *
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void play(JSONObject customData) throws
        TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "play(customData)");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to play a video with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.play(mApiClient, customData)
            .setResultCallback(new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_to_play, result.getStatus().getStatusCode());
                    }
                }

            });
}
 
Example #3
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Stops the playback of media/stream
 *
 * @param customData Optional {@link JSONObject}
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public void stop(JSONObject customData) throws
        TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "stop()");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to stop a stream with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.stop(mApiClient, customData).setResultCallback(
            new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_to_stop, result.getStatus().getStatusCode());
                    }
                }

            }
    );
}
 
Example #4
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Pauses the playback.
 *
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void pause(JSONObject customData) throws
        TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "attempting to pause media");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to pause a video with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.pause(mApiClient, customData)
            .setResultCallback(new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_to_pause, result.getStatus().getStatusCode());
                    }
                }

            });
}
 
Example #5
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Seeks to the given point without changing the state of the player, i.e. after seek is
 * completed, it resumes what it was doing before the start of seek.
 *
 * @param position in milliseconds
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void seek(int position) throws TransientNetworkDisconnectionException,
        NoConnectionException {
    LOGD(TAG, "attempting to seek media");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to seek a video with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.seek(mApiClient,
            position,
            RemoteMediaPlayer.RESUME_STATE_UNCHANGED).
            setResultCallback(new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_seek, result.getStatus().getStatusCode());
                    }
                }

            });
}
 
Example #6
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Seeks to the given point and starts playback regardless of the starting state.
 *
 * @param position in milliseconds
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 * @throws CastException
 */
public void seekAndPlay(int position) throws TransientNetworkDisconnectionException,
        NoConnectionException {
    LOGD(TAG, "attempting to seek media");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to seekAndPlay a video with no active media session");
        throw new NoConnectionException();
    }
    ResultCallback<MediaChannelResult> resultCallback =
            new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_seek, result.getStatus().getStatusCode());
                    }
                }

            };
    mRemoteMediaPlayer.seek(mApiClient,
            position,
            RemoteMediaPlayer.RESUME_STATE_PLAY).setResultCallback(resultCallback);
}
 
Example #7
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Loads a media. For this to succeed, you need to have successfully launched the application.
 *
 * @param media
 * @param autoPlay   If <code>true</code>, playback starts after load
 * @param position   Where to start the playback (only used if autoPlay is <code>true</code>.
 *                   Units is milliseconds.
 * @param customData Optional JSONObject data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void loadMedia(MediaInfo media, boolean autoPlay, int position, JSONObject customData) throws TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "loadMedia: " + media);
  checkConnectivity();
  if (media == null) {
    return;
  }
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to load a video with no active media session");
    throw new NoConnectionException();
  }

  mRemoteMediaPlayer.load(mApiClient, media, autoPlay, position, customData)
      .setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
          if (!result.getStatus().isSuccess()) {
            onFailed(R.string.failed_load, result.getStatus().getStatusCode());
          }

        }
      });
}
 
Example #8
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Resumes the playback from where it was left (can be the beginning).
 *
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void play(JSONObject customData) throws
    TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "play()");
  checkConnectivity();
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to play a video with no active media session");
    throw new NoConnectionException();
  }
  mRemoteMediaPlayer.play(mApiClient)
      .setResultCallback(new ResultCallback<MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
          if (!result.getStatus().isSuccess()) {
            onFailed(R.string.failed_to_play, result.getStatus().getStatusCode());
          }
        }

      });
}
 
Example #9
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Stops the playback of media/stream
 *
 * @param customData Optional {@link JSONObject}
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public void stop(JSONObject customData) throws
    TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "stop()");
  checkConnectivity();
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to stop a stream with no active media session");
    throw new NoConnectionException();
  }
  mRemoteMediaPlayer.stop(mApiClient, customData).setResultCallback(
      new ResultCallback<MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
          if (!result.getStatus().isSuccess()) {
            onFailed(R.string.failed_to_stop, result.getStatus().getStatusCode());
          }
        }

      }
  );
}
 
Example #10
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Pauses the playback.
 *
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void pause(JSONObject customData) throws
    TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "attempting to pause media");
  checkConnectivity();
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to pause a video with no active media session");
    throw new NoConnectionException();
  }
  mRemoteMediaPlayer.pause(mApiClient, customData)
      .setResultCallback(new ResultCallback<MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
          if (!result.getStatus().isSuccess()) {
            onFailed(R.string.failed_to_pause, result.getStatus().getStatusCode());
          }
        }

      });
}
 
Example #11
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Seeks to the given point without changing the state of the player, i.e. after seek is
 * completed, it resumes what it was doing before the start of seek.
 * <p/>
 * position in milliseconds
 */
public void seek(int position) throws TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "attempting to seek media");
  checkConnectivity();
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to seek a video with no active media session");
    throw new NoConnectionException();
  }
  mRemoteMediaPlayer.seek(mApiClient, position, RemoteMediaPlayer.RESUME_STATE_UNCHANGED).
      setResultCallback(new ResultCallback<MediaChannelResult>() {

        @Override
        public void onResult(MediaChannelResult result) {
          if (!result.getStatus().isSuccess()) {
            onFailed(R.string.failed_seek, result.getStatus().getStatusCode());
          }
        }

      });
}
 
Example #12
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * Seeks to the given point and starts playback regardless of the starting state.
 * <p/>
 * position in milliseconds
 */
public void seekAndPlay(int position) throws TransientNetworkDisconnectionException, NoConnectionException {
  CastUtils.LOGD(TAG, "attempting to seek media");
  checkConnectivity();
  if (mRemoteMediaPlayer == null) {
    CastUtils.LOGE(TAG, "Trying to seekAndPlay a video with no active media session");
    throw new NoConnectionException();
  }
  ResultCallback<MediaChannelResult> resultCallback = new ResultCallback<MediaChannelResult>() {

    @Override
    public void onResult(MediaChannelResult result) {
      if (!result.getStatus().isSuccess()) {
        onFailed(R.string.failed_seek, result.getStatus().getStatusCode());
      }
    }

  };
  mRemoteMediaPlayer.seek(mApiClient, position, RemoteMediaPlayer.RESUME_STATE_PLAY)
      .setResultCallback(resultCallback);
}
 
Example #13
Source File: ChromeCastService.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onChromeCastMediaPlayerResult(final Intent response,
                    final MediaChannelResult result, final String message) {
    if (result == null) {
        MessageUtils.setIllegalDeviceStateError(response, message);
        sendResponse(response);
    } else {
        onChromeCastResult(response, result.getStatus(), message);
    }
}
 
Example #14
Source File: ChromeCastMediaPlayer.java    From DeviceConnect-Android with MIT License 2 votes vote down vote up
/**
 * 再生処理の結果を通知する.
 * 
 * @param   response レスポンス
 * @param   result 再生処理結果
 * @param   message 再生処理のステータス
 */
void onChromeCastMediaPlayerResult(final Intent response,
        final MediaChannelResult result, final String message);