Java Code Examples for android.app.Activity#setVolumeControlStream()

The following examples show how to use android.app.Activity#setVolumeControlStream() . These examples are extracted from open source projects. 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 Project: delion   File: MediaSessionTabHelper.java    License: Apache License 2.0 5 votes vote down vote up
void hideNotification() {
    if (mTab == null) {
        return;
    }
    MediaNotificationManager.hide(mTab.getId(), R.id.media_playback_notification);
    Activity activity = getActivityFromTab(mTab);
    if (activity != null) {
        activity.setVolumeControlStream(mPreviousVolumeControlStream);
    }
    mNotificationInfoBuilder = null;
}
 
Example 2
/**
 * This method performs the common steps for hiding the notification. It should only be called
 * by {@link #hideNotificationDelayed()} and {@link #hideNotificationImmediately()}.
 */
private void hideNotificationInternal() {
    MediaNotificationManager.hide(mTab.getId(), R.id.media_playback_notification);
    Activity activity = getActivityFromTab(mTab);
    if (activity != null) {
        activity.setVolumeControlStream(mPreviousVolumeControlStream);
    }
}
 
Example 3
/**
 * This method performs the common steps for hiding the notification. It should only be called
 * by {@link #hideNotificationDelayed()} and {@link #hideNotificationImmediately()}.
 */
private void hideNotificationInternal() {
    MediaNotificationManager.hide(mTab.getId(), R.id.media_playback_notification);
    Activity activity = getActivityFromTab(mTab);
    if (activity != null) {
        activity.setVolumeControlStream(mPreviousVolumeControlStream);
    }
}
 
Example 4
@Override
public void onAttach(@NonNull Context context) {
    super.onAttach(context);
    Log.d(TAG, "onAttach()");

    activity = (Activity) context;
    ttsHost = ((ReadArticleActivity) activity).getTtsHost();

    if (webViewText != null) webViewText.setTtsHost(ttsHost);

    activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    activity.registerReceiver(volumeChangeReceiver, new IntentFilter(VOLUME_CHANGED_ACTION));
}
 
Example 5
Source Project: delion   File: MediaSessionTabHelper.java    License: 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 6
Source Project: Alite   File: AndroidAudio.java    License: GNU General Public License v3.0 4 votes vote down vote up
public AndroidAudio(Activity activity, AndroidFileIO fileIO) {
	activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
	this.assets = activity.getAssets();
	this.fileIO = fileIO;
	this.soundPool = new SoundPool(MAXIMUM_NUMBER_OF_CONCURRENT_SAMPLES, AudioManager.STREAM_MUSIC, 0);
}
 
Example 7
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 8
Source Project: redalert-android   File: Volume.java    License: Apache License 2.0 4 votes vote down vote up
public static void setVolumeKeysAction(Activity context) {
    // Set the appropriate alert stream
    context.setVolumeControlStream(Sound.STREAM_TYPE);
}