org.chromium.chrome.browser.metrics.MediaNotificationUma Java Examples

The following examples show how to use org.chromium.chrome.browser.metrics.MediaNotificationUma. 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
public void show(PlayerState initialState) {
    mMediaRouteController.addUiListener(this);
    // TODO(aberent): investigate why this is necessary, and whether we are handling
    // it correctly. Also add code to restore it when Chrome is resumed.
    mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TYPE,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.class);
    contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
            MediaNotificationUma.SOURCE_MEDIA_FLING);
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setPrivate(false)
            .setIcon(R.drawable.ic_notification_media_route)
            .setContentIntent(contentIntent)
            .setLargeIcon(mMediaRouteController.getPoster())
            .setDefaultLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.remote_notification)
            .setListener(this);
    mState = initialState;
    updateNotification();
    mIsShowing = true;
}
 
Example #2
Source File: CastNotificationControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public void show(PlayerState initialState) {
    mMediaRouteController.addUiListener(this);
    // TODO(aberent): investigate why this is necessary, and whether we are handling
    // it correctly. Also add code to restore it when Chrome is resumed.
    mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TYPE,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.class);
    contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
            MediaNotificationUma.SOURCE_MEDIA_FLING);
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setPrivate(false)
            .setIcon(R.drawable.ic_notification_media_route)
            .setContentIntent(contentIntent)
            .setLargeIcon(mMediaRouteController.getPoster())
            .setDefaultLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.remote_notification)
            .setListener(this);
    mState = initialState;
    updateNotification();
    mIsShowing = true;
}
 
Example #3
Source File: CastNotificationControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public void show(PlayerState initialState) {
    mMediaRouteController.addUiListener(this);
    // TODO(aberent): investigate why this is necessary, and whether we are handling
    // it correctly. Also add code to restore it when Chrome is resumed.
    mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TYPE,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.class);
    contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
            MediaNotificationUma.SOURCE_MEDIA_FLING);
    mNotificationBuilder = new MediaNotificationInfo.Builder()
            .setPaused(false)
            .setPrivate(false)
            .setNotificationSmallIcon(R.drawable.ic_notification_media_route)
            .setContentIntent(contentIntent)
            .setDefaultNotificationLargeIcon(R.drawable.cast_playing_square)
            .setId(R.id.remote_notification)
            .setListener(this);

    updateNotificationBuilderIfPosterIsGoodEnough();
    mState = initialState;

    updateNotification();
    mIsShowing = true;
}
 
Example #4
Source File: ChromeLauncherActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Records metrics gleaned from the Intent.
 */
private void recordIntentMetrics() {
    Intent intent = getIntent();
    IntentHandler.ExternalAppId source =
            IntentHandler.determineExternalIntentSource(getPackageName(), intent);
    if (intent.getPackage() == null && source != IntentHandler.ExternalAppId.CHROME) {
        int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        int maskedFlags = intent.getFlags() & flagsOfInterest;
        sIntentFlagsHistogram.record(maskedFlags);
    }
    MediaNotificationUma.recordClickSource(intent);
}
 
Example #5
Source File: ChromeLauncherActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Records metrics gleaned from the Intent.
 */
private void recordIntentMetrics() {
    Intent intent = getIntent();
    IntentHandler.ExternalAppId source =
            IntentHandler.determineExternalIntentSource(getPackageName(), intent);
    if (intent.getPackage() == null && source != IntentHandler.ExternalAppId.CHROME) {
        int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        int maskedFlags = intent.getFlags() & flagsOfInterest;
        sIntentFlagsHistogram.record(maskedFlags);
    }
    MediaNotificationUma.recordClickSource(intent);
}
 
Example #6
Source File: ChromeLauncherActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Records metrics gleaned from the Intent.
 */
private void recordIntentMetrics() {
    Intent intent = getIntent();
    IntentHandler.ExternalAppId source =
            IntentHandler.determineExternalIntentSource(getPackageName(), intent);
    if (intent.getPackage() == null && source != IntentHandler.ExternalAppId.CHROME) {
        int flagsOfInterest = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        int maskedFlags = intent.getFlags() & flagsOfInterest;
        sIntentFlagsHistogram.record(maskedFlags);
    }
    MediaNotificationUma.recordClickSource(intent);
}
 
Example #7
Source File: MediaSessionTabHelper.java    From delion with Apache License 2.0 4 votes vote down vote up
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;

            // The page's title is used as a placeholder if no title is specified in the
            // metadata.
            if (TextUtils.isEmpty(metadata.getTitle())) {
                mFallbackMetadata = new MediaMetadata(
                        sanitizeMediaTitle(mTab.getTitle()),
                        metadata.getArtist(),
                        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);
            }
        }
    };
}
 
Example #8
Source File: ExpandedControllerActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MediaNotificationUma.recordClickSource(getIntent());

    mMediaRouteController =
            RemoteMediaPlayerController.instance().getCurrentlyPlayingMediaRouteController();

    if (mMediaRouteController == null || mMediaRouteController.routeIsDefaultRoute()) {
        // We don't want to do anything for the default (local) route
        finish();
        return;
    }

    // Make the activity full screen.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // requestWindowFeature must be called before adding content.
    setContentView(R.layout.expanded_cast_controller);
    mHandler = new Handler();

    ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
    rootView.setBackgroundColor(Color.BLACK);

    mMediaRouteController.addUiListener(this);

    // Create transport controller to control video, giving the callback
    // interface to receive actions from.
    mTransportMediator = new TransportMediator(this, mTransportPerformer);

    // Create and initialize the media control UI.
    mMediaController = (MediaController) findViewById(R.id.cast_media_controller);
    mMediaController.setMediaPlayer(mTransportMediator);

    View button = getLayoutInflater().inflate(R.layout.cast_controller_media_route_button,
            rootView, false);

    if (button instanceof FullscreenMediaRouteButton) {
        mMediaRouteButton = (FullscreenMediaRouteButton) button;
        rootView.addView(mMediaRouteButton);
        mMediaRouteButton.bringToFront();
        mMediaRouteButton.initialize(mMediaRouteController);
    } else {
        mMediaRouteButton = null;
    }

    // Initialize the video info.
    setVideoInfo(new RemoteVideoInfo(null, 0, RemoteVideoInfo.PlayerState.STOPPED, 0, null));

    mMediaController.refresh();

    scheduleProgressUpdate();
}
 
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: ExpandedControllerActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MediaNotificationUma.recordClickSource(getIntent());

    mMediaRouteController =
            RemoteMediaPlayerController.instance().getCurrentlyPlayingMediaRouteController();

    if (mMediaRouteController == null || mMediaRouteController.routeIsDefaultRoute()) {
        // We don't want to do anything for the default (local) route
        finish();
        return;
    }

    // Make the activity full screen.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // requestWindowFeature must be called before adding content.
    setContentView(R.layout.expanded_cast_controller);
    mHandler = new Handler();

    ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
    rootView.setBackgroundColor(Color.BLACK);

    mMediaRouteController.addUiListener(this);

    // Create transport controller to control video, giving the callback
    // interface to receive actions from.
    mTransportMediator = new TransportMediator(this, mTransportPerformer);

    // Create and initialize the media control UI.
    mMediaController = (MediaController) findViewById(R.id.cast_media_controller);
    mMediaController.setMediaPlayer(mTransportMediator);

    View button = getLayoutInflater().inflate(R.layout.cast_controller_media_route_button,
            rootView, false);

    if (button instanceof FullscreenMediaRouteButton) {
        mMediaRouteButton = (FullscreenMediaRouteButton) button;
        rootView.addView(mMediaRouteButton);
        mMediaRouteButton.bringToFront();
        mMediaRouteButton.initialize(mMediaRouteController);
    } else {
        mMediaRouteButton = null;
    }

    // Initialize the video info.
    setVideoInfo(new RemoteVideoInfo(null, 0, RemoteVideoInfo.PlayerState.STOPPED, 0, null));

    mMediaController.refresh();

    scheduleProgressUpdate();
}
 
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: MediaSessionTabHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private MediaSessionObserver createMediaSessionObserver(MediaSession mediaSession) {
    return new MediaSessionObserver(mediaSession) {
        @Override
        public void mediaSessionDestroyed() {
            hideNotificationImmediately();
            cleanupMediaSessionObserver();
        }

        @Override
        public void mediaSessionStateChanged(boolean isControllable, boolean isPaused) {
            if (!isControllable) {
                hideNotificationDelayed();
                return;
            }

            Intent contentIntent = Tab.createBringTabToFrontIntent(mTab.getId());
            if (contentIntent != null) {
                contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
                        MediaNotificationUma.SOURCE_MEDIA);
            }

            if (mFallbackTitle == null) mFallbackTitle = sanitizeMediaTitle(mTab.getTitle());
            mCurrentMetadata = getMetadata();
            mCurrentMediaImage = getNotificationImage();
            mNotificationInfoBuilder =
                    new MediaNotificationInfo.Builder()
                            .setMetadata(mCurrentMetadata)
                            .setPaused(isPaused)
                            .setOrigin(mOrigin)
                            .setTabId(mTab.getId())
                            .setPrivate(mTab.isIncognito())
                            .setNotificationSmallIcon(R.drawable.audio_playing)
                            .setNotificationLargeIcon(mCurrentMediaImage)
                            .setDefaultNotificationLargeIcon(R.drawable.audio_playing_square)
                            .setMediaSessionImage(mPageMediaImage)
                            .setActions(MediaNotificationInfo.ACTION_PLAY_PAUSE
                                    | MediaNotificationInfo.ACTION_SWIPEAWAY)
                            .setContentIntent(contentIntent)
                            .setId(R.id.media_playback_notification)
                            .setListener(mControlsListener)
                            .setMediaSessionActions(mMediaSessionActions);

            showNotification();
            Activity activity = getActivityFromTab(mTab);
            if (activity != null) {
                activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
            }
        }

        @Override
        public void mediaSessionMetadataChanged(MediaMetadata metadata) {
            mPageMetadata = metadata;
            mMediaImageManager.downloadImage(
                    (mPageMetadata != null) ? mPageMetadata.getArtwork() : null,
                    MediaSessionTabHelper.this);
            updateNotificationMetadata();
        }

        @Override
        public void mediaSessionActionsChanged(Set<Integer> actions) {
            mMediaSessionActions = actions;
            updateNotificationActions();
        }
    };
}
 
Example #13
Source File: ExpandedControllerActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MediaNotificationUma.recordClickSource(getIntent());

    mMediaRouteController =
            RemoteMediaPlayerController.instance().getCurrentlyPlayingMediaRouteController();

    if (mMediaRouteController == null || mMediaRouteController.routeIsDefaultRoute()) {
        // We don't want to do anything for the default (local) route
        finish();
        return;
    }

    // Make the activity full screen.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // requestWindowFeature must be called before adding content.
    setContentView(R.layout.expanded_cast_controller);
    mHandler = new Handler();

    ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content);
    rootView.setBackgroundColor(Color.BLACK);

    mMediaRouteController.addUiListener(this);

    // Create and initialize the media control UI.
    mMediaController = (MediaController) findViewById(R.id.cast_media_controller);
    mMediaController.setDelegate(mControllerDelegate);

    View button = getLayoutInflater().inflate(R.layout.cast_controller_media_route_button,
            rootView, false);

    if (button instanceof FullscreenMediaRouteButton) {
        mMediaRouteButton = (FullscreenMediaRouteButton) button;
        rootView.addView(mMediaRouteButton);
        mMediaRouteButton.bringToFront();
        mMediaRouteButton.initialize(mMediaRouteController);
    } else {
        mMediaRouteButton = null;
    }

    // Initialize the video info.
    setVideoInfo(new RemoteVideoInfo(null, 0, RemoteVideoInfo.PlayerState.STOPPED, 0, null));

    mMediaController.refresh();

    scheduleProgressUpdate();
}
 
Example #14
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());
}