use of com.google.android.gms.cast.MediaMetadata 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.MediaMetadata in project AntennaPod by AntennaPod.
the class CastUtils method getPlayable.
//TODO make unit tests for all the conversion methods
/**
* Converts {@link MediaInfo} objects into the appropriate implementation of {@link Playable}.
*
* Unless <code>searchFeedMedia</code> is set to <code>false</code>, this method should not run
* on the GUI thread.
*
* @param media The {@link MediaInfo} object to be converted.
* @param searchFeedMedia If set to <code>true</code>, the database will be queried to find a
* {@link FeedMedia} instance that matches {@param media}.
* @return {@link Playable} object in a format proper for casting.
*/
public static Playable getPlayable(MediaInfo media, boolean searchFeedMedia) {
Log.d(TAG, "getPlayable called with searchFeedMedia=" + searchFeedMedia);
if (media == null) {
Log.d(TAG, "MediaInfo object provided is null, not converting to any Playable instance");
return null;
}
MediaMetadata metadata = media.getMetadata();
int version = metadata.getInt(KEY_FORMAT_VERSION);
if (version <= 0 || version > MAX_VERSION_FORWARD_COMPATIBILITY) {
Log.w(TAG, "MediaInfo object obtained from the cast device is not compatible with this" + "version of AntennaPod CastUtils, curVer=" + FORMAT_VERSION_VALUE + ", object version=" + version);
return null;
}
Playable result = null;
if (searchFeedMedia) {
long mediaId = metadata.getInt(KEY_MEDIA_ID);
if (mediaId > 0) {
FeedMedia fMedia = DBReader.getFeedMedia(mediaId);
if (fMedia != null) {
try {
fMedia.loadMetadata();
if (matches(media, fMedia)) {
result = fMedia;
Log.d(TAG, "FeedMedia object obtained matches the MediaInfo provided. id=" + mediaId);
} else {
Log.d(TAG, "FeedMedia object obtained does NOT match the MediaInfo provided. id=" + mediaId);
}
} catch (Playable.PlayableException e) {
Log.e(TAG, "Unable to load FeedMedia metadata to compare with MediaInfo", e);
}
} else {
Log.d(TAG, "Unable to find in database a FeedMedia with id=" + mediaId);
}
}
if (result == null) {
FeedItem feedItem = DBReader.getFeedItem(metadata.getString(KEY_FEED_URL), metadata.getString(KEY_EPISODE_IDENTIFIER));
if (feedItem != null) {
result = feedItem.getMedia();
Log.d(TAG, "Found episode that matches the MediaInfo provided. Using its media, if existing.");
}
}
}
if (result == null) {
List<WebImage> imageList = metadata.getImages();
String imageUrl = null;
if (!imageList.isEmpty()) {
imageUrl = imageList.get(0).getUrl().toString();
}
result = new RemoteMedia(media.getContentId(), metadata.getString(KEY_EPISODE_IDENTIFIER), metadata.getString(KEY_FEED_URL), metadata.getString(MediaMetadata.KEY_SUBTITLE), metadata.getString(MediaMetadata.KEY_TITLE), metadata.getString(KEY_EPISODE_LINK), metadata.getString(MediaMetadata.KEY_ARTIST), imageUrl, metadata.getString(KEY_FEED_WEBSITE), media.getContentType(), metadata.getDate(MediaMetadata.KEY_RELEASE_DATE).getTime());
String notes = metadata.getString(KEY_EPISODE_NOTES);
if (!TextUtils.isEmpty(notes)) {
((RemoteMedia) result).setNotes(notes);
}
Log.d(TAG, "Converted MediaInfo into RemoteMedia");
}
if (result.getDuration() == 0 && media.getStreamDuration() > 0) {
result.setDuration((int) media.getStreamDuration());
}
return result;
}
use of com.google.android.gms.cast.MediaMetadata in project AntennaPod by AntennaPod.
the class CastUtils method matches.
/**
* Compares a {@link MediaInfo} instance with a {@link FeedMedia} one and evaluates whether they
* represent the same podcast episode.
*
* @param info the {@link MediaInfo} object to be compared.
* @param media the {@link FeedMedia} object to be compared.
* @return <true>true</true> if there's a match, <code>false</code> otherwise.
*
* @see RemoteMedia#equals(Object)
*/
public static boolean matches(MediaInfo info, FeedMedia media) {
if (info == null || media == null) {
return false;
}
if (!TextUtils.equals(info.getContentId(), media.getStreamUrl())) {
return false;
}
MediaMetadata metadata = info.getMetadata();
FeedItem fi = media.getItem();
if (fi == null || metadata == null || !TextUtils.equals(metadata.getString(KEY_EPISODE_IDENTIFIER), fi.getItemIdentifier())) {
return false;
}
Feed feed = fi.getFeed();
return feed != null && TextUtils.equals(metadata.getString(KEY_FEED_URL), feed.getDownload_url());
}
use of com.google.android.gms.cast.MediaMetadata in project android-UniversalMusicPlayer by googlesamples.
the class CastPlayback method toCastMediaMetadata.
/**
* Helper method to convert a {@link android.media.MediaMetadata} to a
* {@link com.google.android.gms.cast.MediaInfo} used for sending media to the receiver app.
*
* @param track {@link com.google.android.gms.cast.MediaMetadata}
* @param customData custom data specifies the local mediaId used by the player.
* @return mediaInfo {@link com.google.android.gms.cast.MediaInfo}
*/
private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {
MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString());
mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle() == null ? "" : track.getDescription().getSubtitle().toString());
mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));
mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
WebImage image = new WebImage(new Uri.Builder().encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());
// First image is used by the receiver for showing the audio album art.
mediaMetadata.addImage(image);
// Second image is used by Cast Companion Library on the full screen activity that is shown
// when the cast dialog is clicked.
mediaMetadata.addImage(image);
// noinspection ResourceType
return new MediaInfo.Builder(track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE)).setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mediaMetadata).setCustomData(customData).build();
}
use of com.google.android.gms.cast.MediaMetadata 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() && castManager != null) {
doOnMainThread(() -> Glide.with(MusicService.this).load(getSong()).asBitmap().override(1024, 1024).placeholder(PlaceholderProvider.getInstance().getPlaceHolderDrawable(getSong().name, true)).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);
}
}));
}
}
Aggregations