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);
}
}
};
}
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();
}
}
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);
}
Aggregations