use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException in project zype-android by zype.
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);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException in project zype-android by zype.
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);
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.exceptions.NoConnectionException in project zype-android by zype.
the class VideoCastManager method updateMediaSessionMetadata.
/*
* On ICS and JB, lock screen metadata is one liner: Title - Album Artist - Album. On KitKat, it
* has two lines: Title , Album Artist - Album
*/
private void updateMediaSessionMetadata() {
if ((mMediaSessionCompat == null) || !isFeatureEnabled(FEATURE_LOCKSCREEN)) {
return;
}
try {
MediaInfo info = getRemoteMediaInformation();
if (info == null) {
return;
}
final MediaMetadata mm = info.getMetadata();
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, mContext.getResources().getString(R.string.ccl_casting_to_device, getDeviceName())).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build());
} catch (NotFoundException e) {
LOGE(TAG, "Failed to update Media Session due to resource not found", e);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to update Media Session due to network issues", e);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException in project zype-android by zype.
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();
// mMediaStatus.isShuffleEnabled();
boolean shuffle = false;
onQueueUpdated(queueItems, item, repeatMode, shuffle);
} else {
onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
}
int currentItemId = mMediaStatus.getCurrentItemId();
if (queueItems != null && !queueItems.isEmpty()) {
for (MediaQueueItem item : queueItems) {
LOGD(TAG, "[queue] Queue Item is: " + item.toJson());
}
}
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");
updateMediaSession(false);
switch(mIdleReason) {
case MediaStatus.IDLE_REASON_FINISHED:
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);
}
if (makeUiHidden) {
stopReconnectionService();
}
} else if (mState == MediaStatus.PLAYER_STATE_BUFFERING) {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = buffering");
} else {
LOGD(TAG, "onRemoteMediaPlayerStatusUpdated(): Player status = unknown");
makeUiHidden = true;
}
if (makeUiHidden) {
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.exceptions.NoConnectionException in project zype-android by zype.
the class VideoCastControllerActivity method loadAndSetupViews.
private void loadAndSetupViews() {
mPauseDrawable = getResources().getDrawable(R.drawable.ic_pause_circle_white_80dp);
mPlayDrawable = getResources().getDrawable(R.drawable.ic_play_circle_white_80dp);
mStopDrawable = getResources().getDrawable(R.drawable.ic_stop_circle_white_80dp);
mPageView = findViewById(R.id.pageview);
mPlayPause = (ImageButton) findViewById(R.id.play_pause_toggle);
mLiveText = (TextView) findViewById(R.id.live_text);
mStart = (TextView) findViewById(R.id.start_text);
mEnd = (TextView) findViewById(R.id.end_text);
mSeekbar = (SeekBar) findViewById(R.id.seekbar);
mLine2 = (TextView) findViewById(R.id.textview2);
mLoading = (ProgressBar) findViewById(R.id.progressbar1);
mControllers = findViewById(R.id.controllers);
mClosedCaptionIcon = (ImageButton) findViewById(R.id.cc);
mSkipNext = (ImageButton) findViewById(R.id.next);
mSkipPrevious = (ImageButton) findViewById(R.id.previous);
mPlaybackControls = findViewById(R.id.playback_controls);
mMini = (MiniController) findViewById(R.id.miniController1);
mMini.setCurrentVisibility(false);
setClosedCaptionState(CC_DISABLED);
mPlayPause.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
mListener.onPlayPauseClicked(v);
} catch (TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to toggle playback due to temporary network issue", e);
Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_no_connection_trans);
} catch (NoConnectionException e) {
LOGE(TAG, "Failed to toggle playback due to network issues", e);
Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_no_connection);
} catch (Exception e) {
LOGE(TAG, "Failed to toggle playback due to other issues", e);
Utils.showToast(VideoCastControllerActivity.this, R.string.ccl_failed_perform_action);
}
}
});
mSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
try {
if (mListener != null) {
mListener.onStopTrackingTouch(seekBar);
}
} catch (Exception e) {
LOGE(TAG, "Failed to complete seek", e);
finish();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
try {
if (mListener != null) {
mListener.onStartTrackingTouch(seekBar);
}
} catch (Exception e) {
LOGE(TAG, "Failed to start seek", e);
finish();
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mStart.setText(Utils.formatMillis(progress));
try {
if (mListener != null) {
mListener.onProgressChanged(seekBar, progress, fromUser);
}
} catch (Exception e) {
LOGE(TAG, "Failed to set the progress result", e);
}
}
});
mClosedCaptionIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
showTracksChooserDialog();
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to get the media", e);
}
}
});
mSkipNext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
mListener.onSkipNextClicked(v);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to move to the next item in the queue", e);
}
}
});
mSkipPrevious.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
mListener.onSkipPreviousClicked(v);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to move to the previous item in the queue", e);
}
}
});
}
Aggregations