Search in sources :

Example 31 with MediaMetadata

use of com.google.android.gms.cast.MediaMetadata 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 32 with MediaMetadata

use of com.google.android.gms.cast.MediaMetadata 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 33 with MediaMetadata

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

the class VideoCastNotificationService method build.

/*
     * Build the RemoteViews for the notification. We also need to add the appropriate "back stack"
     * so when user goes into the CastPlayerActivity, she can have a meaningful "back" experience.
     */
private void build(MediaInfo info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    // Playback PendingIntent
    Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
    playbackIntent.setPackage(getPackageName());
    PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0);
    // Disconnect PendingIntent
    Intent stopIntent = new Intent(ACTION_STOP);
    stopIntent.setPackage(getPackageName());
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);
    // Main Content PendingIntent
    Bundle mediaWrapper = Utils.mediaInfoToBundle(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);
    contentIntent.putExtra("media", mediaWrapper);
    // Media metadata
    MediaMetadata metadata = info.getMetadata();
    String castingTo = getResources().getString(R.string.ccl_casting_to_device, mCastManager.getDeviceName());
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(mTargetActivity);
    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }
    PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT);
    int pauseOrStopResourceId = 0;
    if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
        pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp;
    } else {
        pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp;
    }
    int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play;
    NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification).setContentTitle(metadata.getString(MediaMetadata.KEY_TITLE)).setContentText(castingTo).setContentIntent(contentPendingIntent).setLargeIcon(bitmap).addAction(isPlaying ? pauseOrStopResourceId : R.drawable.ic_notification_play_48dp, getString(pauseOrPlayTextResourceId), playbackPendingIntent).addAction(R.drawable.ic_notification_disconnect_24dp, getString(R.string.ccl_disconnect), stopPendingIntent).setStyle(new androidx.media.app.NotificationCompat.MediaStyle().setShowActionsInCompactView(0, 1).setMediaSession(mCastManager.getMediaSessionCompatToken())).setOngoing(true).setShowWhen(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    mNotification = builder.build();
}
Also used : Bundle(android.os.Bundle) TaskStackBuilder(androidx.core.app.TaskStackBuilder) MediaMetadata(com.google.android.gms.cast.MediaMetadata) NotificationCompat(androidx.core.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(androidx.core.app.TaskStackBuilder)

Example 34 with MediaMetadata

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

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(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());
                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) 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 35 with MediaMetadata

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

the class VideoCastManager method updateMediaSessionMetadata.

/*
     * On ICS and JB, lock screen metadata is one liner: Title - Album Artist - Album. On KitKat, it
     * has two lines: Title , Album Artist - Album
     */
private void updateMediaSessionMetadata() {
    if ((mMediaSessionCompat == null) || !isFeatureEnabled(FEATURE_LOCKSCREEN)) {
        return;
    }
    try {
        MediaInfo info = getRemoteMediaInformation();
        if (info == null) {
            return;
        }
        final MediaMetadata mm = info.getMetadata();
        MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
        MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
        mMediaSessionCompat.setMetadata(newBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, mContext.getResources().getString(R.string.ccl_casting_to_device, getDeviceName())).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build());
    } catch (NotFoundException e) {
        LOGE(TAG, "Failed to update Media Session due to resource not found", e);
    } catch (TransientNetworkDisconnectionException | NoConnectionException e) {
        LOGE(TAG, "Failed to update Media Session due to network issues", e);
    }
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) MediaInfo(com.google.android.gms.cast.MediaInfo) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) MediaMetadata(com.google.android.gms.cast.MediaMetadata) NotFoundException(android.content.res.Resources.NotFoundException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

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