use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onTextTrackStyleChanged.
/**
* Signals a change in the Text Track style. Clients should not call this directly.
*/
public void onTextTrackStyleChanged(TextTrackStyle style) {
LOGD(TAG, "onTextTrackStyleChanged() reached");
if (mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaInfo() == null) {
return;
}
mRemoteMediaPlayer.setTextTrackStyle(mApiClient, style).setResultCallback(new ResultCallback<MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
if (!result.getStatus().isSuccess()) {
onFailed(R.string.ccl_failed_to_set_track_style, result.getStatus().getStatusCode());
}
}
});
for (VideoCastConsumer consumer : mVideoConsumers) {
try {
consumer.onTextTrackStyleChanged(style);
} catch (Exception e) {
LOGE(TAG, "onTextTrackStyleChanged(): Failed to inform " + consumer, e);
}
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onVolumeChanged.
private void onVolumeChanged() {
LOGD(TAG, "onVolumeChanged() reached");
double volume;
try {
volume = getVolume();
boolean isMute = isMute();
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onVolumeChanged(volume, isMute);
}
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to get volume", e);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method attachDataChannel.
/*
* If a data namespace was provided when initializing this class, we set things up for a data
* channel
*
* @throws NoConnectionException
* @throws TransientNetworkDisconnectionException
*/
private void attachDataChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
if (TextUtils.isEmpty(mDataNamespace)) {
return;
}
if (mDataChannel != null) {
return;
}
checkConnectivity();
mDataChannel = new MessageReceivedCallback() {
@Override
public void onMessageReceived(CastDevice castDevice, String namespace, String message) {
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onDataMessageReceived(message);
}
}
};
try {
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mDataNamespace, mDataChannel);
} catch (IOException | IllegalStateException e) {
LOGE(TAG, "attachDataChannel()", e);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onRemoteMediaPlayerStatusUpdated.
/*
* This is called by onStatusUpdated() of the RemoteMediaPlayer
*/
private void onRemoteMediaPlayerStatusUpdated() {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated() reached");
if (mApiClient == null || mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaStatus() == null) {
LOGD(TAG, "mApiClient or mRemoteMediaPlayer is null, so will not proceed");
return;
}
mMediaStatus = mRemoteMediaPlayer.getMediaStatus();
List<MediaQueueItem> queueItems = mMediaStatus.getQueueItems();
if (queueItems != null) {
int itemId = mMediaStatus.getCurrentItemId();
MediaQueueItem item = mMediaStatus.getQueueItemById(itemId);
int repeatMode = mMediaStatus.getQueueRepeatMode();
onQueueUpdated(queueItems, item, repeatMode, false);
} else {
onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
}
mState = mMediaStatus.getPlayerState();
mIdleReason = mMediaStatus.getIdleReason();
try {
double volume = getVolume();
boolean isMute = isMute();
boolean makeUiHidden = false;
if (mState == MediaStatus.PLAYER_STATE_PLAYING) {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = playing");
updateMediaSession(true);
long mediaDurationLeft = getMediaTimeRemaining();
startReconnectionService(mediaDurationLeft);
startNotificationService();
} else if (mState == MediaStatus.PLAYER_STATE_PAUSED) {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = paused");
updateMediaSession(false);
startNotificationService();
} else if (mState == MediaStatus.PLAYER_STATE_IDLE) {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = IDLE with reason: " + mIdleReason);
updateMediaSession(false);
switch(mIdleReason) {
case MediaStatus.IDLE_REASON_FINISHED:
if (mMediaStatus.getLoadingItemId() == MediaQueueItem.INVALID_ITEM_ID) {
// we have reached the end of queue
clearMediaSession();
makeUiHidden = true;
}
break;
case MediaStatus.IDLE_REASON_ERROR:
// something bad happened on the cast device
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): IDLE reason = ERROR");
makeUiHidden = true;
clearMediaSession();
onFailed(R.string.ccl_failed_receiver_player_error, NO_STATUS_CODE);
break;
case MediaStatus.IDLE_REASON_CANCELED:
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): IDLE reason = CANCELLED");
makeUiHidden = !isRemoteStreamLive();
break;
case MediaStatus.IDLE_REASON_INTERRUPTED:
if (mMediaStatus.getLoadingItemId() == MediaQueueItem.INVALID_ITEM_ID) {
// we have reached the end of queue
clearMediaSession();
makeUiHidden = true;
}
break;
default:
LOGE(TAG, "onRemoteMediaPlayerStatusUpdated(): Unexpected Idle Reason " + mIdleReason);
}
} else if (mState == MediaStatus.PLAYER_STATE_BUFFERING) {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = buffering");
} else {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = unknown");
makeUiHidden = true;
}
if (makeUiHidden) {
stopReconnectionService();
stopNotificationService();
}
updateMiniControllersVisibility(!makeUiHidden);
updateMiniControllers();
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onRemoteMediaPlayerStatusUpdated();
consumer.onVolumeChanged(volume, isMute);
}
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to get volume state due to network issues", e);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onApplicationDisconnected.
private void onApplicationDisconnected(int errorCode) {
LOGD(TAG, "onApplicationDisconnected() reached with error code: " + errorCode);
mApplicationErrorCode = errorCode;
updateMediaSession(false);
if (mMediaSessionCompat != null && isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
mMediaRouter.setMediaSessionCompat(null);
}
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onApplicationDisconnected(errorCode);
}
if (mMediaRouter != null) {
LOGD(TAG, "onApplicationDisconnected(): Cached RouteInfo: " + getRouteInfo());
LOGD(TAG, "onApplicationDisconnected(): Selected RouteInfo: " + mMediaRouter.getSelectedRoute());
if (getRouteInfo() == null || mMediaRouter.getSelectedRoute().equals(getRouteInfo())) {
LOGD(TAG, "onApplicationDisconnected(): Setting route to default");
mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
}
}
onDeviceSelected(null, /* CastDevice */
null);
updateMiniControllersVisibility(false);
stopNotificationService();
}
Aggregations