org.chromium.chrome.browser.media.ui.MediaNotificationManager Java Examples

The following examples show how to use org.chromium.chrome.browser.media.ui.MediaNotificationManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CastNotificationControl.java    From delion with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #2
Source File: CastNotificationControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #3
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void updateNotification() {
    // Nothing shown yet, nothing to update.
    if (mNotificationBuilder == null) return;

    mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", ""));
    if (mTabOrigin != null) mNotificationBuilder.setOrigin(mTabOrigin);

    if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) {
        mNotificationBuilder.setPaused(mState != PlayerState.PLAYING);
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                | MediaNotificationInfo.ACTION_PLAY_PAUSE);
        MediaNotificationManager.show(mNotificationBuilder.build());
    } else if (mState == PlayerState.LOADING) {
        mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
        MediaNotificationManager.show(mNotificationBuilder.build());
    } else {
        hide();
    }
}
 
Example #4
Source File: CastSessionImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void stopApplication() {
    if (mStoppingApplication) return;

    if (isApiClientInvalid()) return;

    mStoppingApplication = true;
    Cast.CastApi.stopApplication(mApiClient, mSessionId)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    mMessageHandler.onApplicationStopped();
                    // TODO(avayvod): handle a failure to stop the application.
                    // https://crbug.com/535577

                    Set<String> namespaces = new HashSet<String>(mNamespaces);
                    for (String namespace : namespaces) unregisterNamespace(namespace);
                    mNamespaces.clear();

                    mSessionId = null;
                    mApiClient = null;

                    mRouteProvider.onSessionClosed();
                    mStoppingApplication = false;

                    MediaNotificationManager.clear(R.id.presentation_notification);
                }
            });
}
 
Example #5
Source File: CastSessionImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void stopApplication() {
    if (mStoppingApplication) return;

    if (isApiClientInvalid()) return;

    mStoppingApplication = true;
    Cast.CastApi.stopApplication(mApiClient, mSessionId)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    mMessageHandler.onApplicationStopped();
                    // TODO(avayvod): handle a failure to stop the application.
                    // https://crbug.com/535577

                    Set<String> namespaces = new HashSet<String>(mNamespaces);
                    for (String namespace : namespaces) unregisterNamespace(namespace);
                    mNamespaces.clear();

                    mSessionId = null;
                    mApiClient = null;

                    mRouteProvider.onSessionClosed();
                    mStoppingApplication = false;

                    MediaNotificationManager.clear(R.id.presentation_notification);
                }
            });
}
 
Example #6
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateNotificationBuilderIfPosterIsGoodEnough() {
    Bitmap poster = mMediaRouteController.getPoster();
    if (MediaNotificationManager.isBitmapSuitableAsMediaImage(poster)) {
        mNotificationBuilder.setNotificationLargeIcon(poster);
        mNotificationBuilder.setMediaSessionImage(poster);
    }
}
 
Example #7
Source File: CastSessionImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void stopApplication() {
    if (mStoppingApplication) return;

    if (isApiClientInvalid()) return;

    mStoppingApplication = true;
    Cast.CastApi.stopApplication(mApiClient, mSessionId)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    mMessageHandler.onApplicationStopped();
                    // TODO(avayvod): handle a failure to stop the application.
                    // https://crbug.com/535577

                    Set<String> namespaces = new HashSet<String>(mNamespaces);
                    for (String namespace : namespaces) unregisterNamespace(namespace);
                    mNamespaces.clear();

                    mSessionId = null;
                    mApiClient = null;

                    mRouteProvider.onSessionClosed();
                    mStoppingApplication = false;

                    MediaNotificationManager.clear(R.id.presentation_notification);
                }
            });
}
 
Example #8
Source File: CastNotificationControl.java    From delion with Apache License 2.0 4 votes vote down vote up
public void hide() {
    mIsShowing = false;
    MediaNotificationManager.hide(Tab.INVALID_TAB_ID, R.id.remote_notification);
    mAudioManager.abandonAudioFocus(this);
    mMediaRouteController.removeUiListener(this);
}
 
Example #9
Source File: CastSessionImpl.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes a new {@link CastSessionImpl} instance.
 * @param apiClient The Google Play Services client used to create the session.
 * @param sessionId The session identifier to use with the Cast SDK.
 * @param origin The origin of the frame requesting the route.
 * @param tabId The id of the tab containing the frame requesting the route.
 * @param isIncognito Whether the route is beging requested from an Incognito profile.
 * @param source The {@link MediaSource} corresponding to this session.
 * @param routeProvider The {@link CastMediaRouteProvider} instance managing this session.
 */
public CastSessionImpl(
        GoogleApiClient apiClient,
        String sessionId,
        ApplicationMetadata metadata,
        String applicationStatus,
        CastDevice castDevice,
        String origin,
        int tabId,
        boolean isIncognito,
        MediaSource source,
        CastMediaRouteProvider routeProvider) {
    mSessionId = sessionId;
    mRouteProvider = routeProvider;
    mApiClient = apiClient;
    mSource = source;
    mApplicationMetadata = metadata;
    mApplicationStatus = applicationStatus;
    mCastDevice = castDevice;
    mMessageHandler = mRouteProvider.getMessageHandler();
    mMessageChannel = new CastMessagingChannel(this);
    updateNamespaces();

    final Context context = ContextUtils.getApplicationContext();

    if (mNamespaces.contains(CastMessageHandler.MEDIA_NAMESPACE)) {
        mMediaPlayer = new RemoteMediaPlayer();
        mMediaPlayer.setOnStatusUpdatedListener(
                new RemoteMediaPlayer.OnStatusUpdatedListener() {
                    @Override
                    public void onStatusUpdated() {
                        MediaStatus mediaStatus = mMediaPlayer.getMediaStatus();
                        if (mediaStatus == null) return;

                        int playerState = mediaStatus.getPlayerState();
                        if (playerState == MediaStatus.PLAYER_STATE_PAUSED
                                || playerState == MediaStatus.PLAYER_STATE_PLAYING) {
                            mNotificationBuilder.setPaused(
                                    playerState != MediaStatus.PLAYER_STATE_PLAYING);
                            mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                                    | MediaNotificationInfo.ACTION_PLAY_PAUSE);
                        } else {
                            mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
                        }
                        MediaNotificationManager.show(context, mNotificationBuilder.build());
                    }
                });
        mMediaPlayer.setOnMetadataUpdatedListener(
                new RemoteMediaPlayer.OnMetadataUpdatedListener() {
                    @Override
                    public void onMetadataUpdated() {
                        setNotificationMetadata(mNotificationBuilder);
                        MediaNotificationManager.show(context, mNotificationBuilder.build());
                    }
                });
    }

    Intent contentIntent = Tab.createBringTabToFrontIntent(tabId);
    if (contentIntent != null) {
        contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
                MediaNotificationUma.SOURCE_PRESENTATION);
    }
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setOrigin(origin)
            // TODO(avayvod): the same session might have more than one tab id. Should we track
            // the last foreground alive tab and update the notification with it?
            .setTabId(tabId)
            .setPrivate(isIncognito)
            .setActions(MediaNotificationInfo.ACTION_STOP)
            .setContentIntent(contentIntent)
            .setIcon(R.drawable.ic_notification_media_route)
            .setDefaultLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.presentation_notification)
            .setListener(this);
    setNotificationMetadata(mNotificationBuilder);
    MediaNotificationManager.show(context, mNotificationBuilder.build());
}
 
Example #10
Source File: CastNotificationControl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public void hide() {
    mIsShowing = false;
    MediaNotificationManager.hide(Tab.INVALID_TAB_ID, R.id.remote_notification);
    mAudioManager.abandonAudioFocus(this);
    mMediaRouteController.removeUiListener(this);
}
 
Example #11
Source File: CastSessionImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes a new {@link CastSessionImpl} instance.
 * @param apiClient The Google Play Services client used to create the session.
 * @param sessionId The session identifier to use with the Cast SDK.
 * @param origin The origin of the frame requesting the route.
 * @param tabId The id of the tab containing the frame requesting the route.
 * @param isIncognito Whether the route is beging requested from an Incognito profile.
 * @param source The {@link MediaSource} corresponding to this session.
 * @param routeProvider The {@link CastMediaRouteProvider} instance managing this session.
 */
public CastSessionImpl(
        GoogleApiClient apiClient,
        String sessionId,
        ApplicationMetadata metadata,
        String applicationStatus,
        CastDevice castDevice,
        String origin,
        int tabId,
        boolean isIncognito,
        MediaSource source,
        CastMediaRouteProvider routeProvider) {
    mSessionId = sessionId;
    mRouteProvider = routeProvider;
    mApiClient = apiClient;
    mSource = source;
    mApplicationMetadata = metadata;
    mApplicationStatus = applicationStatus;
    mCastDevice = castDevice;
    mMessageHandler = mRouteProvider.getMessageHandler();
    mMessageChannel = new CastMessagingChannel(this);
    updateNamespaces();

    final Context context = ContextUtils.getApplicationContext();

    if (mNamespaces.contains(CastMessageHandler.MEDIA_NAMESPACE)) {
        mMediaPlayer = new RemoteMediaPlayer();
        mMediaPlayer.setOnStatusUpdatedListener(
                new RemoteMediaPlayer.OnStatusUpdatedListener() {
                    @Override
                    public void onStatusUpdated() {
                        MediaStatus mediaStatus = mMediaPlayer.getMediaStatus();
                        if (mediaStatus == null) return;

                        int playerState = mediaStatus.getPlayerState();
                        if (playerState == MediaStatus.PLAYER_STATE_PAUSED
                                || playerState == MediaStatus.PLAYER_STATE_PLAYING) {
                            mNotificationBuilder.setPaused(
                                    playerState != MediaStatus.PLAYER_STATE_PLAYING);
                            mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                                    | MediaNotificationInfo.ACTION_PLAY_PAUSE);
                        } else {
                            mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
                        }
                        MediaNotificationManager.show(context, mNotificationBuilder.build());
                    }
                });
        mMediaPlayer.setOnMetadataUpdatedListener(
                new RemoteMediaPlayer.OnMetadataUpdatedListener() {
                    @Override
                    public void onMetadataUpdated() {
                        setNotificationMetadata(mNotificationBuilder);
                        MediaNotificationManager.show(context, mNotificationBuilder.build());
                    }
                });
    }

    Intent contentIntent = Tab.createBringTabToFrontIntent(tabId);
    if (contentIntent != null) {
        contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
                MediaNotificationUma.SOURCE_PRESENTATION);
    }
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setOrigin(origin)
            // TODO(avayvod): the same session might have more than one tab id. Should we track
            // the last foreground alive tab and update the notification with it?
            .setTabId(tabId)
            .setPrivate(isIncognito)
            .setActions(MediaNotificationInfo.ACTION_STOP)
            .setContentIntent(contentIntent)
            .setIcon(R.drawable.ic_notification_media_route)
            .setDefaultLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.presentation_notification)
            .setListener(this);
    setNotificationMetadata(mNotificationBuilder);
    MediaNotificationManager.show(context, mNotificationBuilder.build());
}
 
Example #12
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public void hide() {
    mIsShowing = false;
    MediaNotificationManager.hide(Tab.INVALID_TAB_ID, R.id.remote_notification);
    mAudioManager.abandonAudioFocus(this);
    mMediaRouteController.removeUiListener(this);
}
 
Example #13
Source File: CastSessionImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes a new {@link CastSessionImpl} instance.
 * @param apiClient The Google Play Services client used to create the session.
 * @param sessionId The session identifier to use with the Cast SDK.
 * @param origin The origin of the frame requesting the route.
 * @param tabId The id of the tab containing the frame requesting the route.
 * @param isIncognito Whether the route is beging requested from an Incognito profile.
 * @param source The {@link MediaSource} corresponding to this session.
 * @param routeProvider The {@link CastMediaRouteProvider} instance managing this session.
 */
public CastSessionImpl(
        GoogleApiClient apiClient,
        String sessionId,
        ApplicationMetadata metadata,
        String applicationStatus,
        CastDevice castDevice,
        String origin,
        int tabId,
        boolean isIncognito,
        MediaSource source,
        CastMediaRouteProvider routeProvider) {
    mSessionId = sessionId;
    mRouteProvider = routeProvider;
    mApiClient = apiClient;
    mSource = source;
    mApplicationMetadata = metadata;
    mApplicationStatus = applicationStatus;
    mCastDevice = castDevice;
    mMessageHandler = mRouteProvider.getMessageHandler();
    mMessageChannel = new CastMessagingChannel(this);
    updateNamespaces();

    if (mNamespaces.contains(CastMessageHandler.MEDIA_NAMESPACE)) {
        mMediaPlayer = new RemoteMediaPlayer();
        mMediaPlayer.setOnStatusUpdatedListener(
                new RemoteMediaPlayer.OnStatusUpdatedListener() {
                    @Override
                    public void onStatusUpdated() {
                        MediaStatus mediaStatus = mMediaPlayer.getMediaStatus();
                        if (mediaStatus == null) return;

                        int playerState = mediaStatus.getPlayerState();
                        if (playerState == MediaStatus.PLAYER_STATE_PAUSED
                                || playerState == MediaStatus.PLAYER_STATE_PLAYING) {
                            mNotificationBuilder.setPaused(
                                    playerState != MediaStatus.PLAYER_STATE_PLAYING);
                            mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
                                    | MediaNotificationInfo.ACTION_PLAY_PAUSE);
                        } else {
                            mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP);
                        }
                        MediaNotificationManager.show(mNotificationBuilder.build());
                    }
                });
        mMediaPlayer.setOnMetadataUpdatedListener(
                new RemoteMediaPlayer.OnMetadataUpdatedListener() {
                    @Override
                    public void onMetadataUpdated() {
                        setNotificationMetadata(mNotificationBuilder);
                        MediaNotificationManager.show(mNotificationBuilder.build());
                    }
                });
    }

    Intent contentIntent = Tab.createBringTabToFrontIntent(tabId);
    if (contentIntent != null) {
        contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
                MediaNotificationUma.SOURCE_PRESENTATION);
    }
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setOrigin(origin)
            // TODO(avayvod): the same session might have more than one tab id. Should we track
            // the last foreground alive tab and update the notification with it?
            .setTabId(tabId)
            .setPrivate(isIncognito)
            .setActions(MediaNotificationInfo.ACTION_STOP)
            .setContentIntent(contentIntent)
            .setNotificationSmallIcon(R.drawable.ic_notification_media_route)
            .setDefaultNotificationLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.presentation_notification)
            .setListener(this);
    setNotificationMetadata(mNotificationBuilder);
    MediaNotificationManager.show(mNotificationBuilder.build());
}