use of com.google.android.gms.cast.MediaInfo in project android-UniversalMusicPlayer by googlesamples.
the class CastPlayback method setMetadataFromRemote.
private void setMetadataFromRemote() {
// app joins an existing session while the Chromecast was playing a queue.
try {
MediaInfo mediaInfo = mRemoteMediaClient.getMediaInfo();
if (mediaInfo == null) {
return;
}
JSONObject customData = mediaInfo.getCustomData();
if (customData != null && customData.has(ITEM_ID)) {
String remoteMediaId = customData.getString(ITEM_ID);
if (!TextUtils.equals(mCurrentMediaId, remoteMediaId)) {
mCurrentMediaId = remoteMediaId;
if (mCallback != null) {
mCallback.setCurrentMediaId(remoteMediaId);
}
updateLastKnownStreamPosition();
}
}
} catch (JSONException e) {
LogHelper.e(TAG, e, "Exception processing update metadata");
}
}
use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.
the class MusicService method prepareChromeCastLoad.
void prepareChromeCastLoad(int position, boolean autoPlay) {
if (currentSong == null) {
return;
}
if (TextUtils.isEmpty(currentSong.path)) {
return;
}
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
metadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, getAlbumArtistName());
metadata.putString(MediaMetadata.KEY_ALBUM_TITLE, getAlbumName());
metadata.putString(MediaMetadata.KEY_TITLE, getSongName());
metadata.addImage(new WebImage(Uri.parse("http://" + ShuttleUtils.getIpAddr() + ":5000" + "/image/" + getSongId())));
MediaInfo selectedMedia = new MediaInfo.Builder("http://" + ShuttleUtils.getIpAddr() + ":5000" + "/audio/" + getSongId()).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setContentType("audio/*").setMetadata(metadata).build();
if (ShuttleUtils.isUpgraded() && mCastManager != null) {
doOnMainThread(() -> {
Glide.with(MusicService.this).load(getSong()).asBitmap().override(1024, 1024).placeholder(GlideUtils.getLargePlaceHolderResId()).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
loadRemoteMedia(selectedMedia, position, autoPlay, resource, null);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
loadRemoteMedia(selectedMedia, position, autoPlay, null, errorDrawable);
}
});
});
}
}
use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.
the class VideoCastManager method updateMiniController.
/**
* Updates the information and state of a MiniController.
*
* @throws TransientNetworkDisconnectionException
* @throws NoConnectionException
*/
private void updateMiniController(IMiniController controller) throws TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
checkRemoteMediaPlayerAvailable();
if (mRemoteMediaPlayer.getStreamDuration() > 0 || isRemoteStreamLive()) {
MediaInfo mediaInfo = getRemoteMediaInformation();
MediaMetadata mm = mediaInfo.getMetadata();
controller.setStreamType(mediaInfo.getStreamType());
controller.setPlaybackStatus(mState, mIdleReason);
controller.setSubtitle(mContext.getResources().getString(R.string.ccl_casting_to_device, mDeviceName));
controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE));
controller.setIcon(Utils.getImageUri(mediaInfo, 0));
}
}
use of com.google.android.gms.cast.MediaInfo in project Shuttle by timusus.
the class MiniController method setUpcomingItem.
@Override
public void setUpcomingItem(MediaQueueItem item) {
mUpcomingItem = item;
if (item != null) {
MediaInfo mediaInfo = item.getMedia();
if (mediaInfo != null) {
MediaMetadata metadata = mediaInfo.getMetadata();
setUpcomingTitle(metadata.getString(MediaMetadata.KEY_TITLE));
setUpcomingIcon(Utils.getImageUri(mediaInfo, 0));
}
} else {
setUpcomingTitle("");
setUpcomingIcon((Uri) null);
}
}
use of com.google.android.gms.cast.MediaInfo in project AntennaPod by AntennaPod.
the class CastManager 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);
}
Aggregations