Search in sources :

Example 11 with MediaMetadata

use of com.google.android.gms.cast.MediaMetadata in project Shuttle by timusus.

the class VideoCastControllerFragment method updateMetadata.

private void updateMetadata() {
    Uri imageUrl = null;
    if (mSelectedMedia == null) {
        if (mMediaAuthService != null) {
            imageUrl = Utils.getImageUri(mMediaAuthService.getMediaInfo(), 1);
        }
    } else {
        imageUrl = Utils.getImageUri(mSelectedMedia, 1);
    }
    showImage(imageUrl);
    if (mSelectedMedia == null) {
        return;
    }
    MediaMetadata mm = mSelectedMedia.getMetadata();
    mCastController.setTitle(mm.getString(MediaMetadata.KEY_TITLE) != null ? mm.getString(MediaMetadata.KEY_TITLE) : "");
    boolean isLive = mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE;
    mCastController.adjustControllersForLiveStream(isLive);
}
Also used : MediaMetadata(com.google.android.gms.cast.MediaMetadata) Uri(android.net.Uri)

Example 12 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 13 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 14 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)

Aggregations

MediaMetadata (com.google.android.gms.cast.MediaMetadata)14 MediaInfo (com.google.android.gms.cast.MediaInfo)9 WebImage (com.google.android.gms.common.images.WebImage)7 Uri (android.net.Uri)4 Calendar (java.util.Calendar)4 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)3 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)3 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)3 Bitmap (android.graphics.Bitmap)2 MediaTrack (com.google.android.gms.cast.MediaTrack)2 Feed (de.danoeh.antennapod.core.feed.Feed)2 Playable (de.danoeh.antennapod.core.util.playback.Playable)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 NotFoundException (android.content.res.Resources.NotFoundException)1 SQLiteException (android.database.sqlite.SQLiteException)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1