Search in sources :

Example 31 with MediaMetadataCompat

use of android.support.v4.media.MediaMetadataCompat 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

MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)31 Test (org.junit.Test)13 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)8 Bitmap (android.graphics.Bitmap)6 Uri (android.net.Uri)4 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)4 Bundle (android.os.Bundle)3 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)3 Builder (com.google.android.gms.cast.Cast.CastOptions.Builder)3 MediaInfo (com.google.android.gms.cast.MediaInfo)3 FetchBitmapTask (com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Intent (android.content.Intent)2 NotFoundException (android.content.res.Resources.NotFoundException)2 RemoteException (android.os.RemoteException)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2