use of com.google.android.gms.cast.MediaInfo 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.gms.cast.MediaInfo in project Shuttle by timusus.
the class VideoCastManager method isRemoteStreamLive.
/**
* Determines if the media that is loaded remotely is a live stream or not.
*
* @throws TransientNetworkDisconnectionException
* @throws NoConnectionException
*/
public final boolean isRemoteStreamLive() throws TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
MediaInfo info = getRemoteMediaInformation();
return (info != null) && (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE);
}
use of com.google.android.gms.cast.MediaInfo 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);
}
}
use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.
the class VideoCastManager method getRemoteMediaUrl.
/**
* Returns the url for the movie that is currently playing on the remote device. If there is no
* connection, this will return <code>null</code>.
*
* @throws NoConnectionException If no connectivity to the device exists
* @throws TransientNetworkDisconnectionException If framework is still trying to recover from
* a possibly transient loss of network
*/
public String getRemoteMediaUrl() throws TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
if (mRemoteMediaPlayer != null && mRemoteMediaPlayer.getMediaInfo() != null) {
MediaInfo info = mRemoteMediaPlayer.getMediaInfo();
mRemoteMediaPlayer.getMediaStatus().getPlayerState();
return info.getContentId();
}
throw new NoConnectionException();
}
use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.
the class VideoCastControllerFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mCastConsumer = new MyCastConsumer();
Bundle bundle = getArguments();
if (bundle == null) {
return;
}
Bundle extras = bundle.getBundle(EXTRAS);
Bundle mediaWrapper = extras.getBundle(VideoCastManager.EXTRA_MEDIA);
// Retain this fragment across configuration changes.
setRetainInstance(true);
mCastManager.addTracksSelectedListener(this);
boolean explicitStartActivity = mCastManager.getPreferenceAccessor().getBooleanFromPreference(VideoCastManager.PREFS_KEY_START_ACTIVITY, false);
if (explicitStartActivity) {
mIsFresh = true;
}
mCastManager.getPreferenceAccessor().saveBooleanToPreference(VideoCastManager.PREFS_KEY_START_ACTIVITY, false);
mCastController.setNextPreviousVisibilityPolicy(mCastManager.getCastConfiguration().getNextPrevVisibilityPolicy());
if (extras.getBoolean(VideoCastManager.EXTRA_HAS_AUTH)) {
if (mIsFresh) {
mOverallState = OverallState.AUTHORIZING;
mMediaAuthService = mCastManager.getMediaAuthService();
handleMediaAuthTask(mMediaAuthService);
showImage(Utils.getImageUri(mMediaAuthService.getMediaInfo(), 1));
}
} else if (mediaWrapper != null) {
mOverallState = OverallState.PLAYBACK;
boolean shouldStartPlayback = extras.getBoolean(VideoCastManager.EXTRA_SHOULD_START);
String customDataStr = extras.getString(VideoCastManager.EXTRA_CUSTOM_DATA);
JSONObject customData = null;
if (!TextUtils.isEmpty(customDataStr)) {
try {
customData = new JSONObject(customDataStr);
} catch (JSONException e) {
LOGE(TAG, "Failed to unmarshalize custom data string: customData=" + customDataStr, e);
}
}
MediaInfo info = Utils.bundleToMediaInfo(mediaWrapper);
int startPoint = extras.getInt(VideoCastManager.EXTRA_START_POINT, 0);
onReady(info, shouldStartPlayback && explicitStartActivity, startPoint, customData);
}
}
Aggregations