use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onRemoteMediaPreloadStatusUpdated.
private void onRemoteMediaPreloadStatusUpdated() {
MediaQueueItem item = null;
mMediaStatus = mRemoteMediaPlayer != null ? mRemoteMediaPlayer.getMediaStatus() : null;
if (mMediaStatus != null) {
item = mMediaStatus.getQueueItemById(mMediaStatus.getPreloadedItemId());
}
mPreLoadingItem = item;
updateMiniControllersVisibilityForUpcoming(item);
LOGD(TAG, "onRemoteMediaPreloadStatusUpdated() " + item);
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onRemoteMediaPreloadStatusUpdated(item);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onApplicationConnectionFailed.
@Override
public void onApplicationConnectionFailed(int errorCode) {
LOGD(TAG, "onApplicationConnectionFailed() reached with errorCode: " + errorCode);
mApplicationErrorCode = errorCode;
if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
if (errorCode == CastStatusCodes.APPLICATION_NOT_RUNNING) {
// while trying to re-establish session, we found out that the app is not running
// so we need to disconnect
mReconnectionStatus = RECONNECTION_STATUS_INACTIVE;
onDeviceSelected(null, /* CastDevice */
null);
}
} else {
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onApplicationConnectionFailed(errorCode);
}
onDeviceSelected(null, /* CastDevice */
null);
if (mMediaRouter != null) {
LOGD(TAG, "onApplicationConnectionFailed(): Setting route to default");
mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
}
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onQueueUpdated.
/*
* This is called by onQueueStatusUpdated() of RemoteMediaPlayer
*/
private void onQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) {
LOGD(TAG, "onQueueUpdated() reached");
LOGD(TAG, String.format("Queue Items size: %d, Item: %s, Repeat Mode: %d, Shuffle: %s", queueItems == null ? 0 : queueItems.size(), item, repeatMode, shuffle));
if (queueItems != null) {
mMediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(queueItems), item, shuffle, repeatMode);
} else {
mMediaQueue = new MediaQueue(new CopyOnWriteArrayList<MediaQueueItem>(), null, false, MediaStatus.REPEAT_MODE_REPEAT_OFF);
}
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onMediaQueueUpdated(queueItems, item, repeatMode, shuffle);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onApplicationConnected.
@Override
protected void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId + ", and mReconnectionStatus=" + mReconnectionStatus);
mApplicationErrorCode = NO_APPLICATION_ERROR;
if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
// we have tried to reconnect and successfully launched the app, so
// it is time to select the route and make the cast icon happy :-)
List<RouteInfo> routes = mMediaRouter.getRoutes();
if (routes != null) {
String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
for (RouteInfo routeInfo : routes) {
if (routeId.equals(routeInfo.getId())) {
// found the right route
LOGD(TAG, "Found the correct route during reconnection attempt");
mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
mMediaRouter.selectRoute(routeInfo);
break;
}
}
}
}
startNotificationService();
try {
attachDataChannel();
attachMediaChannel();
mSessionId = sessionId;
// saving device for future retrieval; we only save the last session info
mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, mSessionId);
mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
if (!result.getStatus().isSuccess()) {
onFailed(R.string.ccl_failed_status_request, result.getStatus().getStatusCode());
}
}
});
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onApplicationConnected(appMetadata, mSessionId, wasLaunched);
}
} catch (TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
onFailed(R.string.ccl_failed_no_connection_trans, NO_STATUS_CODE);
} catch (NoConnectionException e) {
LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
onFailed(R.string.ccl_failed_no_connection, NO_STATUS_CODE);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumer in project Shuttle by timusus.
the class VideoCastManager method onRemoteMediaPlayerMetadataUpdated.
/*
* This is called by onMetadataUpdated() of RemoteMediaPlayer
*/
public void onRemoteMediaPlayerMetadataUpdated() {
LOGD(TAG, "onRemoteMediaPlayerMetadataUpdated() reached");
updateMediaSessionMetadata();
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onRemoteMediaPlayerMetadataUpdated();
}
try {
updateLockScreenImage(getRemoteMediaInformation());
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to update lock screen metadata due to a network issue", e);
}
}
Aggregations