use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException in project Shuttle by timusus.
the class VideoMediaRouteControllerDialog method updateMetadata.
private void updateMetadata() {
MediaInfo info;
try {
info = mCastManager.getRemoteMediaInformation();
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
hideControls(true, R.string.ccl_failed_no_connection_short);
return;
}
if (info == null) {
hideControls(true, R.string.ccl_no_media_info);
return;
}
mStreamType = info.getStreamType();
hideControls(false, 0);
MediaMetadata mm = info.getMetadata();
mTitle.setText(mm.getString(MediaMetadata.KEY_TITLE));
mSubTitle.setText(mm.getString(MediaMetadata.KEY_SUBTITLE));
setIcon(mm.hasImages() ? mm.getImages().get(0).getUrl() : null);
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException in project Shuttle by timusus.
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);
((MiniController) findViewById(R.id.miniController1)).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);
}
}
});
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException in project Shuttle by timusus.
the class VideoCastManager method getCastControllerPendingIntent.
/*
* Returns a PendingIntent that can open the target activity for controlling the cast experience
*/
private PendingIntent getCastControllerPendingIntent() {
try {
Bundle mediaWrapper = Utils.mediaInfoToBundle(getRemoteMediaInformation());
Intent contentIntent = new Intent(mContext, mTargetActivity);
contentIntent.putExtra(VideoCastManager.EXTRA_MEDIA, mediaWrapper);
return PendingIntent.getActivity(mContext, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "getCastControllerPendingIntent(): Failed to get the remote media information");
}
return null;
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException 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.exceptions.TransientNetworkDisconnectionException in project Shuttle by timusus.
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(CastConfiguration.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);
MediaMetadataCompat metadata = 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())).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, mm.getString(MediaMetadata.KEY_SUBTITLE)).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build();
mMediaSessionCompat.setMetadata(metadata);
Uri iconUri = mm.hasImages() ? mm.getImages().get(0).getUrl() : null;
if (iconUri == null) {
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bm).build());
} else {
if (mMediaSessionIconFetchTask != null) {
mMediaSessionIconFetchTask.cancel(true);
}
mMediaSessionIconFetchTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null && mMediaSessionCompat != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap).build());
}
mMediaSessionIconFetchTask = null;
}
};
mMediaSessionIconFetchTask.execute(iconUri);
}
} 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);
}
}
Aggregations