Search in sources :

Example 11 with WebImage

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

the class BaseVideoActivity method getLocalMediaInfo.

private MediaInfo getLocalMediaInfo(int type, @Nullable VideoData videoData) {
    String url = getNetworkUrl(type, videoData);
    if (url == null) {
        throw new IllegalStateException(" URL == null");
    }
    MediaInfo mediaInfo;
    String contentType;
    int mediaType;
    if (type == PlayerFragment.TYPE_AUDIO_WEB || type == PlayerFragment.TYPE_AUDIO_LOCAL || type == PlayerFragment.TYPE_AUDIO_LIVE) {
        mediaType = MediaMetadata.MEDIA_TYPE_MUSIC_TRACK;
        contentType = "audio/mp4";
    } else {
        mediaType = MediaMetadata.MEDIA_TYPE_MOVIE;
        if (url.contains(".mp4")) {
            contentType = "video/mp4";
        } else {
            contentType = "application/x-mpegurl";
        }
    }
    MediaMetadata movieMetadata = new MediaMetadata(mediaType);
    if (videoData != null) {
        movieMetadata.putString(MediaMetadata.KEY_TITLE, videoData.getTitle());
    } else {
        movieMetadata.putString(MediaMetadata.KEY_TITLE, "Live");
    }
    if (videoData != null && videoData.getThumbnails() != null && videoData.getThumbnails().size() > 0) {
        Thumbnail thumbnail = videoData.getThumbnails().get(0);
        movieMetadata.addImage(new WebImage(Uri.parse(thumbnail.getUrl())));
    } else {
        movieMetadata.addImage(new WebImage(Uri.EMPTY));
    }
    mediaInfo = new MediaInfo.Builder(url).setContentType(contentType).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(movieMetadata).build();
    return mediaInfo;
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) Thumbnail(com.zype.android.webapi.model.video.Thumbnail)

Example 12 with WebImage

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

Example 13 with WebImage

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

the class Utils method mediaInfoToBundle.

/**
 * Builds and returns a {@link Bundle} which contains a select subset of data in the
 * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this
 * container bundle to pass around from one activity to another.
 *
 * @see <code>bundleToMediaInfo()</code>
 */
public static Bundle mediaInfoToBundle(MediaInfo info) {
    if (info == null) {
        return null;
    }
    MediaMetadata md = info.getMetadata();
    Bundle wrapper = new Bundle();
    wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE));
    wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE));
    wrapper.putString(MediaMetadata.KEY_ALBUM_TITLE, md.getString(MediaMetadata.KEY_ALBUM_TITLE));
    wrapper.putString(MediaMetadata.KEY_ALBUM_ARTIST, md.getString(MediaMetadata.KEY_ALBUM_ARTIST));
    wrapper.putString(MediaMetadata.KEY_COMPOSER, md.getString(MediaMetadata.KEY_COMPOSER));
    wrapper.putString(MediaMetadata.KEY_SERIES_TITLE, md.getString(MediaMetadata.KEY_SERIES_TITLE));
    wrapper.putInt(MediaMetadata.KEY_SEASON_NUMBER, md.getInt(MediaMetadata.KEY_SEASON_NUMBER));
    wrapper.putInt(MediaMetadata.KEY_EPISODE_NUMBER, md.getInt(MediaMetadata.KEY_EPISODE_NUMBER));
    Calendar releaseCalendar = md.getDate(MediaMetadata.KEY_RELEASE_DATE);
    if (releaseCalendar != null) {
        long releaseMillis = releaseCalendar.getTimeInMillis();
        wrapper.putLong(MediaMetadata.KEY_RELEASE_DATE, releaseMillis);
    }
    wrapper.putInt(KEY_MEDIA_TYPE, info.getMetadata().getMediaType());
    wrapper.putString(KEY_URL, info.getContentId());
    wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO));
    wrapper.putString(KEY_CONTENT_TYPE, info.getContentType());
    wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType());
    wrapper.putLong(KEY_STREAM_DURATION, info.getStreamDuration());
    if (!md.getImages().isEmpty()) {
        ArrayList<String> urls = new ArrayList<>();
        for (WebImage img : md.getImages()) {
            urls.add(img.getUrl().toString());
        }
        wrapper.putStringArrayList(KEY_IMAGES, urls);
    }
    JSONObject customData = info.getCustomData();
    if (customData != null) {
        wrapper.putString(KEY_CUSTOM_DATA, customData.toString());
    }
    if (info.getMediaTracks() != null && !info.getMediaTracks().isEmpty()) {
        try {
            JSONArray jsonArray = new JSONArray();
            for (MediaTrack mt : info.getMediaTracks()) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(KEY_TRACK_NAME, mt.getName());
                jsonObject.put(KEY_TRACK_CONTENT_ID, mt.getContentId());
                jsonObject.put(KEY_TRACK_ID, mt.getId());
                jsonObject.put(KEY_TRACK_LANGUAGE, mt.getLanguage());
                jsonObject.put(KEY_TRACK_TYPE, mt.getType());
                jsonObject.put(KEY_TRACK_CONTENT_TYPE, mt.getContentType());
                if (mt.getSubtype() != MediaTrack.SUBTYPE_UNKNOWN) {
                    jsonObject.put(KEY_TRACK_SUBTYPE, mt.getSubtype());
                }
                if (mt.getCustomData() != null) {
                    jsonObject.put(KEY_TRACK_CUSTOM_DATA, mt.getCustomData().toString());
                }
                jsonArray.put(jsonObject);
            }
            wrapper.putString(KEY_TRACKS_DATA, jsonArray.toString());
        } catch (JSONException e) {
            LOGE(TAG, "mediaInfoToBundle(): Failed to convert Tracks data to json", e);
        }
    }
    return wrapper;
}
Also used : MediaTrack(com.google.android.gms.cast.MediaTrack) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) JSONException(org.json.JSONException)

Example 14 with WebImage

use of com.google.android.gms.common.images.WebImage in project butter-android by butterproject.

the class CastService method displayImage.

@Override
public void displayImage(String url, String mimeType, String title, String description, String iconSrc, LaunchListener listener) {
    MediaMetadata mMediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO);
    mMediaMetadata.putString(MediaMetadata.KEY_TITLE, title);
    mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, description);
    if (iconSrc != null) {
        Uri iconUri = Uri.parse(iconSrc);
        WebImage image = new WebImage(iconUri, 100, 100);
        mMediaMetadata.addImage(image);
    }
    com.google.android.gms.cast.MediaInfo mediaInformation = new com.google.android.gms.cast.MediaInfo.Builder(url).setContentType(mimeType).setStreamType(com.google.android.gms.cast.MediaInfo.STREAM_TYPE_NONE).setMetadata(mMediaMetadata).setStreamDuration(0).setCustomData(null).build();
    playMedia(mediaInformation, applicationID, listener);
}
Also used : MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) Uri(android.net.Uri)

Example 15 with WebImage

use of com.google.android.gms.common.images.WebImage in project butter-android by butterproject.

the class CastService method playMedia.

public void playMedia(String url, String subsUrl, String mimeType, String title, String description, String iconSrc, boolean shouldLoop, LaunchListener listener) {
    MediaMetadata mMediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
    mMediaMetadata.putString(MediaMetadata.KEY_TITLE, title);
    mMediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, description);
    if (iconSrc != null) {
        Uri iconUri = Uri.parse(iconSrc);
        WebImage image = new WebImage(iconUri, 100, 100);
        mMediaMetadata.addImage(image);
    }
    List<MediaTrack> mediaTracks = new ArrayList<>();
    if (subsUrl != null) {
        MediaTrack subtitle = new MediaTrack.Builder(1, MediaTrack.TYPE_TEXT).setName("Subtitle").setSubtype(MediaTrack.SUBTYPE_SUBTITLES).setContentId(subsUrl).setContentType("text/vtt").setLanguage("en").build();
        mediaTracks.add(subtitle);
    }
    com.google.android.gms.cast.MediaInfo mediaInformation = new com.google.android.gms.cast.MediaInfo.Builder(url).setContentType(mimeType).setStreamType(com.google.android.gms.cast.MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mMediaMetadata).setStreamDuration(1000).setCustomData(null).setMediaTracks(mediaTracks).build();
    playMedia(mediaInformation, applicationID, listener);
}
Also used : ArrayList(java.util.ArrayList) WebImage(com.google.android.gms.common.images.WebImage) Uri(android.net.Uri) MediaTrack(com.google.android.gms.cast.MediaTrack) MediaInfo(com.connectsdk.core.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata)

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