Search in sources :

Example 16 with WebImage

use of com.google.android.gms.common.images.WebImage 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 17 with WebImage

use of com.google.android.gms.common.images.WebImage in project Timber by naman14.

the class TimberCastHelper method startCasting.

public static void startCasting(CastSession castSession, Song song) {
    String ipAddress = TimberUtils.getIPAddress(true);
    URL baseUrl;
    try {
        baseUrl = new URL("http", ipAddress, Constants.CAST_SERVER_PORT, "");
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return;
    }
    String songUrl = baseUrl.toString() + "/song?id=" + song.id;
    String albumArtUrl = baseUrl.toString() + "/albumart?id=" + song.albumId;
    MediaMetadata musicMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    musicMetadata.putString(MediaMetadata.KEY_TITLE, song.title);
    musicMetadata.putString(MediaMetadata.KEY_ARTIST, song.artistName);
    musicMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, song.albumName);
    musicMetadata.putInt(MediaMetadata.KEY_TRACK_NUMBER, song.trackNumber);
    musicMetadata.addImage(new WebImage(Uri.parse(albumArtUrl)));
    try {
        MediaInfo mediaInfo = new MediaInfo.Builder(songUrl).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setContentType("audio/mpeg").setMetadata(musicMetadata).setStreamDuration(song.duration).build();
        RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
        remoteMediaClient.load(mediaInfo, true, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MediaInfo(com.google.android.gms.cast.MediaInfo) RemoteMediaClient(com.google.android.gms.cast.framework.media.RemoteMediaClient) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Example 18 with WebImage

use of com.google.android.gms.common.images.WebImage in project AntennaPod by AntennaPod.

the class MediaInfoCreator method from.

public static MediaInfo from(RemoteMedia media) {
    MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
    metadata.putString(MediaMetadata.KEY_TITLE, media.getEpisodeTitle());
    metadata.putString(MediaMetadata.KEY_SUBTITLE, media.getFeedTitle());
    if (!TextUtils.isEmpty(media.getImageLocation())) {
        metadata.addImage(new WebImage(Uri.parse(media.getImageLocation())));
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(media.getPubDate());
    metadata.putDate(MediaMetadata.KEY_RELEASE_DATE, calendar);
    if (!TextUtils.isEmpty(media.getFeedAuthor())) {
        metadata.putString(MediaMetadata.KEY_ARTIST, media.getFeedAuthor());
    }
    if (!TextUtils.isEmpty(media.getFeedUrl())) {
        metadata.putString(CastUtils.KEY_FEED_URL, media.getFeedUrl());
    }
    if (!TextUtils.isEmpty(media.getFeedLink())) {
        metadata.putString(CastUtils.KEY_FEED_WEBSITE, media.getFeedLink());
    }
    if (!TextUtils.isEmpty(media.getEpisodeIdentifier())) {
        metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, media.getEpisodeIdentifier());
    } else {
        metadata.putString(CastUtils.KEY_EPISODE_IDENTIFIER, media.getDownloadUrl());
    }
    if (!TextUtils.isEmpty(media.getEpisodeLink())) {
        metadata.putString(CastUtils.KEY_EPISODE_LINK, media.getEpisodeLink());
    }
    String notes = media.getNotes();
    if (notes != null) {
        metadata.putString(CastUtils.KEY_EPISODE_NOTES, notes);
    }
    // Default id value
    metadata.putInt(CastUtils.KEY_MEDIA_ID, 0);
    metadata.putInt(CastUtils.KEY_FORMAT_VERSION, CastUtils.FORMAT_VERSION_VALUE);
    metadata.putString(CastUtils.KEY_STREAM_URL, media.getStreamUrl());
    MediaInfo.Builder builder = new MediaInfo.Builder(media.getDownloadUrl()).setContentType(media.getMimeType()).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(metadata);
    if (media.getDuration() > 0) {
        builder.setStreamDuration(media.getDuration());
    }
    return builder.build();
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) Calendar(java.util.Calendar) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage)

Example 19 with WebImage

use of com.google.android.gms.common.images.WebImage 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

WebImage (com.google.android.gms.common.images.WebImage)19 MediaMetadata (com.google.android.gms.cast.MediaMetadata)17 MediaInfo (com.google.android.gms.cast.MediaInfo)11 Uri (android.net.Uri)7 Calendar (java.util.Calendar)6 MediaTrack (com.google.android.gms.cast.MediaTrack)5 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Bitmap (android.graphics.Bitmap)3 ArrayList (java.util.ArrayList)3 Point (android.graphics.Point)2 Bundle (android.os.Bundle)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)2 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)2 FetchBitmapTask (com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)2 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)2 Playable (de.danoeh.antennapod.core.util.playback.Playable)2 SQLiteException (android.database.sqlite.SQLiteException)1 Drawable (android.graphics.drawable.Drawable)1