Search in sources :

Example 1 with MediaMetadata

use of org.chromium.content_public.common.MediaMetadata in project AndroidChromium by JackyAndroid.

the class MediaSessionTabHelper method createWebContentsObserver.

private WebContentsObserver createWebContentsObserver(WebContents webContents) {
    return new WebContentsObserver(webContents) {

        @Override
        public void destroy() {
            hideNotification();
            super.destroy();
        }

        @Override
        public void mediaSessionStateChanged(boolean isControllable, boolean isPaused, MediaMetadata metadata) {
            if (!isControllable) {
                hideNotification();
                return;
            }
            mFallbackMetadata = null;
            // metadata.
            if (metadata == null || TextUtils.isEmpty(metadata.getTitle())) {
                mFallbackMetadata = new MediaMetadata(sanitizeMediaTitle(mTab.getTitle()), metadata == null ? "" : metadata.getArtist(), metadata == null ? "" : metadata.getAlbum());
                metadata = mFallbackMetadata;
            }
            Intent contentIntent = Tab.createBringTabToFrontIntent(mTab.getId());
            if (contentIntent != null) {
                contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME, MediaNotificationUma.SOURCE_MEDIA);
            }
            mNotificationInfoBuilder = new MediaNotificationInfo.Builder().setMetadata(metadata).setPaused(isPaused).setOrigin(mOrigin).setTabId(mTab.getId()).setPrivate(mTab.isIncognito()).setIcon(R.drawable.audio_playing).setLargeIcon(mFavicon).setDefaultLargeIcon(R.drawable.audio_playing_square).setActions(MediaNotificationInfo.ACTION_PLAY_PAUSE | MediaNotificationInfo.ACTION_SWIPEAWAY).setContentIntent(contentIntent).setId(R.id.media_playback_notification).setListener(mControlsListener);
            MediaNotificationManager.show(ContextUtils.getApplicationContext(), mNotificationInfoBuilder.build());
            Activity activity = getActivityFromTab(mTab);
            if (activity != null) {
                activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
            }
        }
    };
}
Also used : MediaMetadata(org.chromium.content_public.common.MediaMetadata) Activity(android.app.Activity) Intent(android.content.Intent) WebContentsObserver(org.chromium.content_public.browser.WebContentsObserver)

Example 2 with MediaMetadata

use of org.chromium.content_public.common.MediaMetadata in project AndroidChromium by JackyAndroid.

the class CastNotificationControl method updateNotification.

private void updateNotification() {
    // Nothing shown yet, nothing to update.
    if (mNotificationBuilder == null)
        return;
    mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", ""));
    if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) {
        mNotificationBuilder.setPaused(mState != PlayerState.PLAYING);
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP | MediaNotificationInfo.ACTION_PLAY_PAUSE);
        MediaNotificationManager.show(mContext, mNotificationBuilder.build());
    } else if (mState == PlayerState.LOADING) {
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
        MediaNotificationManager.show(mContext, mNotificationBuilder.build());
    } else {
        hide();
    }
}
Also used : MediaMetadata(org.chromium.content_public.common.MediaMetadata)

Example 3 with MediaMetadata

use of org.chromium.content_public.common.MediaMetadata in project AndroidChromium by JackyAndroid.

the class CastSessionImpl method setNotificationMetadata.

private void setNotificationMetadata(MediaNotificationInfo.Builder builder) {
    MediaMetadata notificationMetadata = new MediaMetadata("", "", "");
    builder.setMetadata(notificationMetadata);
    if (mCastDevice != null)
        notificationMetadata.setTitle(mCastDevice.getFriendlyName());
    if (mMediaPlayer == null)
        return;
    com.google.android.gms.cast.MediaInfo info = mMediaPlayer.getMediaInfo();
    if (info == null)
        return;
    com.google.android.gms.cast.MediaMetadata metadata = info.getMetadata();
    if (metadata == null)
        return;
    String title = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_TITLE);
    if (title != null)
        notificationMetadata.setTitle(title);
    String artist = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ARTIST);
    if (artist == null) {
        artist = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_ARTIST);
    }
    if (artist != null)
        notificationMetadata.setArtist(artist);
    String album = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_TITLE);
    if (album != null)
        notificationMetadata.setAlbum(album);
}
Also used : MediaMetadata(org.chromium.content_public.common.MediaMetadata)

Aggregations

MediaMetadata (org.chromium.content_public.common.MediaMetadata)3 Activity (android.app.Activity)1 Intent (android.content.Intent)1 WebContentsObserver (org.chromium.content_public.browser.WebContentsObserver)1