Search in sources :

Example 16 with MediaMetadata

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);
    }
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata)

Example 17 with MediaMetadata

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;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage)

Example 18 with MediaMetadata

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());
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) MediaMetadata(com.google.android.gms.cast.MediaMetadata) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 19 with MediaMetadata

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();
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) Uri(android.net.Uri)

Example 20 with MediaMetadata

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);
            }
        }));
    }
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) MediaInfo(com.google.android.gms.cast.MediaInfo) Drawable(android.graphics.drawable.Drawable) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SQLiteException(android.database.sqlite.SQLiteException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) ConcurrentModificationException(java.util.ConcurrentModificationException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Aggregations

MediaMetadata (com.google.android.gms.cast.MediaMetadata)36 MediaInfo (com.google.android.gms.cast.MediaInfo)22 WebImage (com.google.android.gms.common.images.WebImage)19 Uri (android.net.Uri)10 Calendar (java.util.Calendar)6 MediaTrack (com.google.android.gms.cast.MediaTrack)5 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)5 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)5 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Bundle (android.os.Bundle)3 MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)3 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)3 ArrayList (java.util.ArrayList)3 NotFoundException (android.content.res.Resources.NotFoundException)2 Bitmap (android.graphics.Bitmap)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)2 MediaInfo (com.connectsdk.core.MediaInfo)2 Thumbnail (com.zype.android.webapi.model.video.Thumbnail)2