Search in sources :

Example 26 with MediaMetadata

use of com.google.android.gms.cast.MediaMetadata in project HybridMediaPlayer by mkaflowski.

the class ExoMediaPlayer method buildMediaQueueItem.

private MediaQueueItem buildMediaQueueItem(String url, MediaSourceInfo mediaSourceInfo, int position) {
    if (mediaSourceInfo == null)
        mediaSourceInfo = MediaSourceInfo.PLACEHOLDER;
    MediaMetadata movieMetadata = new MediaMetadata(mediaSourceInfo.isVideo() ? MediaMetadata.MEDIA_TYPE_MOVIE : MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    movieMetadata.putString(MediaMetadata.KEY_TITLE, mediaSourceInfo.getTitle());
    movieMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, mediaSourceInfo.getAuthor());
    movieMetadata.putInt(MediaMetadata.KEY_TRACK_NUMBER, position);
    movieMetadata.addImage(new WebImage(Uri.parse(mediaSourceInfo.getImageUrl())));
    MediaInfo mediaInfo = new MediaInfo.Builder(url).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setContentType(mediaSourceInfo.isVideo() ? MimeTypes.VIDEO_UNKNOWN : MimeTypes.AUDIO_UNKNOWN).setMetadata(movieMetadata).build();
    return new MediaQueueItem.Builder(mediaInfo).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) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 27 with MediaMetadata

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

the class DefaultMediaItemConverter method toMediaItem.

@Override
public MediaItem toMediaItem(MediaQueueItem mediaQueueItem) {
    @Nullable MediaInfo mediaInfo = mediaQueueItem.getMedia();
    Assertions.checkNotNull(mediaInfo);
    com.google.android.exoplayer2.MediaMetadata.Builder metadataBuilder = new com.google.android.exoplayer2.MediaMetadata.Builder();
    @Nullable MediaMetadata metadata = mediaInfo.getMetadata();
    if (metadata != null) {
        if (metadata.containsKey(MediaMetadata.KEY_TITLE)) {
            metadataBuilder.setTitle(metadata.getString(MediaMetadata.KEY_TITLE));
        }
        if (metadata.containsKey(MediaMetadata.KEY_SUBTITLE)) {
            metadataBuilder.setSubtitle(metadata.getString(MediaMetadata.KEY_SUBTITLE));
        }
        if (metadata.containsKey(MediaMetadata.KEY_ARTIST)) {
            metadataBuilder.setArtist(metadata.getString(MediaMetadata.KEY_ARTIST));
        }
        if (metadata.containsKey(MediaMetadata.KEY_ALBUM_ARTIST)) {
            metadataBuilder.setAlbumArtist(metadata.getString(MediaMetadata.KEY_ALBUM_ARTIST));
        }
        if (metadata.containsKey(MediaMetadata.KEY_ALBUM_TITLE)) {
            metadataBuilder.setArtist(metadata.getString(MediaMetadata.KEY_ALBUM_TITLE));
        }
        if (!metadata.getImages().isEmpty()) {
            metadataBuilder.setArtworkUri(metadata.getImages().get(0).getUrl());
        }
        if (metadata.containsKey(MediaMetadata.KEY_COMPOSER)) {
            metadataBuilder.setComposer(metadata.getString(MediaMetadata.KEY_COMPOSER));
        }
        if (metadata.containsKey(MediaMetadata.KEY_DISC_NUMBER)) {
            metadataBuilder.setDiscNumber(metadata.getInt(MediaMetadata.KEY_DISC_NUMBER));
        }
        if (metadata.containsKey(MediaMetadata.KEY_TRACK_NUMBER)) {
            metadataBuilder.setTrackNumber(metadata.getInt(MediaMetadata.KEY_TRACK_NUMBER));
        }
    }
    // `mediaQueueItem` came from `toMediaQueueItem()` so the custom JSON data must be set.
    return getMediaItem(Assertions.checkNotNull(mediaInfo.getCustomData()), metadataBuilder.build());
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) Nullable(androidx.annotation.Nullable)

Example 28 with MediaMetadata

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

the class DefaultMediaItemConverter method toMediaQueueItem.

@Override
public MediaQueueItem toMediaQueueItem(MediaItem mediaItem) {
    Assertions.checkNotNull(mediaItem.localConfiguration);
    if (mediaItem.localConfiguration.mimeType == null) {
        throw new IllegalArgumentException("The item must specify its mimeType");
    }
    MediaMetadata metadata = new MediaMetadata(MimeTypes.isAudio(mediaItem.localConfiguration.mimeType) ? MediaMetadata.MEDIA_TYPE_MUSIC_TRACK : MediaMetadata.MEDIA_TYPE_MOVIE);
    if (mediaItem.mediaMetadata.title != null) {
        metadata.putString(MediaMetadata.KEY_TITLE, mediaItem.mediaMetadata.title.toString());
    }
    if (mediaItem.mediaMetadata.subtitle != null) {
        metadata.putString(MediaMetadata.KEY_SUBTITLE, mediaItem.mediaMetadata.subtitle.toString());
    }
    if (mediaItem.mediaMetadata.artist != null) {
        metadata.putString(MediaMetadata.KEY_ARTIST, mediaItem.mediaMetadata.artist.toString());
    }
    if (mediaItem.mediaMetadata.albumArtist != null) {
        metadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, mediaItem.mediaMetadata.albumArtist.toString());
    }
    if (mediaItem.mediaMetadata.albumTitle != null) {
        metadata.putString(MediaMetadata.KEY_ALBUM_TITLE, mediaItem.mediaMetadata.albumTitle.toString());
    }
    if (mediaItem.mediaMetadata.artworkUri != null) {
        metadata.addImage(new WebImage(mediaItem.mediaMetadata.artworkUri));
    }
    if (mediaItem.mediaMetadata.composer != null) {
        metadata.putString(MediaMetadata.KEY_COMPOSER, mediaItem.mediaMetadata.composer.toString());
    }
    if (mediaItem.mediaMetadata.discNumber != null) {
        metadata.putInt(MediaMetadata.KEY_DISC_NUMBER, mediaItem.mediaMetadata.discNumber);
    }
    if (mediaItem.mediaMetadata.trackNumber != null) {
        metadata.putInt(MediaMetadata.KEY_TRACK_NUMBER, mediaItem.mediaMetadata.trackNumber);
    }
    MediaInfo mediaInfo = new MediaInfo.Builder(mediaItem.localConfiguration.uri.toString()).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setContentType(mediaItem.localConfiguration.mimeType).setMetadata(metadata).setCustomData(getCustomData(mediaItem)).build();
    return new MediaQueueItem.Builder(mediaInfo).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) MediaQueueItem(com.google.android.gms.cast.MediaQueueItem)

Example 29 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.model.feed.FeedItem) MediaMetadata(com.google.android.gms.cast.MediaMetadata) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 30 with MediaMetadata

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

the class CastUtils method makeRemoteMedia.

/**
 * Converts {@link MediaInfo} objects into the appropriate implementation of {@link Playable}.
 * @return {@link Playable} object in a format proper for casting.
 */
public static Playable makeRemoteMedia(MediaInfo media) {
    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;
    }
    List<WebImage> imageList = metadata.getImages();
    String imageUrl = null;
    if (!imageList.isEmpty()) {
        imageUrl = imageList.get(0).getUrl().toString();
    }
    String notes = metadata.getString(KEY_EPISODE_NOTES);
    RemoteMedia 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(), notes);
    if (result.getDuration() == 0 && media.getStreamDuration() > 0) {
        result.setDuration((int) media.getStreamDuration());
    }
    return result;
}
Also used : RemoteMedia(de.danoeh.antennapod.model.playback.RemoteMedia) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage)

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