Search in sources :

Example 11 with MediaInfo

use of com.google.android.gms.cast.MediaInfo in project android-UniversalMusicPlayer by googlesamples.

the class CastPlayback method setMetadataFromRemote.

private void setMetadataFromRemote() {
    // app joins an existing session while the Chromecast was playing a queue.
    try {
        MediaInfo mediaInfo = mRemoteMediaClient.getMediaInfo();
        if (mediaInfo == null) {
            return;
        }
        JSONObject customData = mediaInfo.getCustomData();
        if (customData != null && customData.has(ITEM_ID)) {
            String remoteMediaId = customData.getString(ITEM_ID);
            if (!TextUtils.equals(mCurrentMediaId, remoteMediaId)) {
                mCurrentMediaId = remoteMediaId;
                if (mCallback != null) {
                    mCallback.setCurrentMediaId(remoteMediaId);
                }
                updateLastKnownStreamPosition();
            }
        }
    } catch (JSONException e) {
        LogHelper.e(TAG, e, "Exception processing update metadata");
    }
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 12 with MediaInfo

use of com.google.android.gms.cast.MediaInfo 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() && mCastManager != null) {
        doOnMainThread(() -> {
            Glide.with(MusicService.this).load(getSong()).asBitmap().override(1024, 1024).placeholder(GlideUtils.getLargePlaceHolderResId()).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 : 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) SQLiteException(android.database.sqlite.SQLiteException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 13 with MediaInfo

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

the class VideoCastManager method updateMiniController.

/**
     * Updates the information and state of a MiniController.
     *
     * @throws TransientNetworkDisconnectionException
     * @throws NoConnectionException
     */
private void updateMiniController(IMiniController controller) throws TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    checkRemoteMediaPlayerAvailable();
    if (mRemoteMediaPlayer.getStreamDuration() > 0 || isRemoteStreamLive()) {
        MediaInfo mediaInfo = getRemoteMediaInformation();
        MediaMetadata mm = mediaInfo.getMetadata();
        controller.setStreamType(mediaInfo.getStreamType());
        controller.setPlaybackStatus(mState, mIdleReason);
        controller.setSubtitle(mContext.getResources().getString(R.string.ccl_casting_to_device, mDeviceName));
        controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE));
        controller.setIcon(Utils.getImageUri(mediaInfo, 0));
    }
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata)

Example 14 with MediaInfo

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

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

the class CastManager method isRemoteStreamLive.

/**
     * Determines if the media that is loaded remotely is a live stream or not.
     *
     * @throws TransientNetworkDisconnectionException
     * @throws NoConnectionException
     */
public final boolean isRemoteStreamLive() throws TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    MediaInfo info = getRemoteMediaInformation();
    return (info != null) && (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE);
}
Also used : MediaInfo(com.google.android.gms.cast.MediaInfo)

Aggregations

MediaInfo (com.google.android.gms.cast.MediaInfo)16 MediaMetadata (com.google.android.gms.cast.MediaMetadata)9 WebImage (com.google.android.gms.common.images.WebImage)5 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)5 JSONObject (org.json.JSONObject)4 Uri (android.net.Uri)3 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)3 Calendar (java.util.Calendar)3 JSONException (org.json.JSONException)3 Bitmap (android.graphics.Bitmap)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)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 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)1 MediaTrack (com.google.android.gms.cast.MediaTrack)1 CastException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)1 FetchBitmapTask (com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)1