Example usage for android.media AudioManager STREAM_MUSIC

List of usage examples for android.media AudioManager STREAM_MUSIC

Introduction

In this page you can find the example usage for android.media AudioManager STREAM_MUSIC.

Prototype

int STREAM_MUSIC

To view the source code for android.media AudioManager STREAM_MUSIC.

Click Source Link

Document

Used to identify the volume of audio streams for music playback

Usage

From source file:com.guayaba.tapir.ui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}// w  w w. j a v  a  2 s .c  o  m
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialze the theme resources
    mResources = new ThemeUtils(this);
    // Set the overflow style
    mResources.setOverflowStyle(this);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the image fetcher/cache
    mImageFetcher = ApolloUtils.getImageFetcher(this);

    // Initialize the handler used to update the current time
    mTimeHandler = new TimeHandler(this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    final ActionBar actionBar = getActionBar();
    mResources.themeActionBar(actionBar, getString(R.string.app_name));
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();
}

From source file:com.boko.vimusic.ui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}//ww w.  j a v  a 2  s.  c  o  m
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialze the theme resources
    mResources = new ThemeUtils(this);
    // Set the overflow style
    mResources.setOverflowStyle(this);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the image fetcher/cache
    mImageFetcher = CommonUtils.getImageFetcher(this);

    // Initialize the handler used to update the current time
    mTimeHandler = new TimeHandler(this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    final ActionBar actionBar = getActionBar();
    mResources.themeActionBar(actionBar, getString(R.string.app_name));
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();
}

From source file:io.syng.fragment.WebViewFragment.java

protected void init() {
    webView = makeWebView();//from w ww  . jav  a2  s.  c  om
    createViews();
    if (!webView.isInitialized()) {
        webView.init(cordovaInterface, pluginEntries, preferences);
    }
    webView.getView().requestFocusFromTouch();
    cordovaInterface.onCordovaInit(webView.getPluginManager());
    //webView.clearCache();
    android.webkit.CookieManager.getInstance().removeAllCookie();

    // Wire the hardware volume controls to control media if desired.
    String volumePref = preferences.getString("DefaultVolumeStream", "");
    if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
        getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }
    BaseActivity activity = (BaseActivity) getActivity();
    activity.hideToolbar(2);
    gestureDetector = new GestureDetector(webView.getContext(), this);
    webView.getView().setOnTouchListener(this);
}

From source file:com.bt.download.android.gui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}/*w w  w  .  j  av  a  2 s.c  om*/
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the image fetcher/cache
    mImageFetcher = ImageFetcher.getInstance(this);

    // Initialize the handler used to update the current time
    mTimeHandler = new TimeHandler(this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Theme the action bar
    setTitle(R.string.now_playing);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);

    // Set the layout
    setContentView(R.layout.activity_player_base);

    // Cache all the items
    initPlaybackControls();

    initGestures();
    mPlayPauseButton.setOnLongClickListener(new StopListener(this));
}

From source file:com.BibleQuote.ui.ReaderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reader);//from  w  w  w  .j av a  2 s.  c o m

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    BibleQuoteApp app = (BibleQuoteApp) getApplication();
    myLibrarian = app.getLibrarian();

    mAsyncManager = app.getAsyncManager();
    mAsyncManager.handleRetainedTask(mTask, this);

    initialyzeViews();
    updateActivityMode();

    BibleReference osisLink;
    Intent intent = getIntent();
    if (intent != null && intent.getData() != null) {
        osisLink = new BibleReference(intent.getData());
    } else {
        osisLink = new BibleReference(PreferenceHelper.restoreStateString("last_read"));
    }

    if (!myLibrarian.isOSISLinkValid(osisLink)) {
        onChooseChapterClick();
    } else {
        openChapterFromLink(osisLink);
    }
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!CameraUtilities.getIsCameraAvailable(getPackageManager())) {
        Toast.makeText(PaperChainsActivity.this, getString(R.string.hint_no_camera), Toast.LENGTH_SHORT).show();
        finish();//from   w w  w. j a va 2 s .com
        return;
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);

    setViews(R.id.viewfinder_view, R.id.preview_view, R.id.image_view);
    setResizeImageToView(false); // we want the high quality image

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // set up action bar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(R.string.title_activity_capture);
    actionBar.setDisplayShowTitleEnabled(true);

    int resultPointColour = getResources().getColor(R.color.accent);
    ((ViewfinderView) findViewById(R.id.viewfinder_view)).setResultPointColour(resultPointColour);

    // set up SoundCloud API wrappers (without a user token - for playback only, initially)
    setupSoundCloudApiWrappers();

    mCurrentMode = MODE_CAPTURE;

    // set up a zoomable view for the photo
    mImageView = (PaperChainsView) findViewById(R.id.image_view);
    mZoomControl = new DynamicZoomControl();
    mImageView.setZoomState(mZoomControl.getZoomState());
    mZoomControl.setAspectQuotient(mImageView.getAspectQuotient());
    mZoomListener = new LongPressZoomListener(PaperChainsActivity.this);
    mZoomListener.setZoomControl(mZoomControl);

    // set up buttons/handlers
    mImageView.setOnTouchListener(mZoomListener);
    mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onImageClick();
        }
    });
    mImageView.setScribbleCallback(new PaperChainsView.ScribbleCallback() {
        @Override
        public void scribbleCompleted(Path scribble) {
            processScribble(scribble);
        }
    });

    mRecordButton = (AudioRecorderCircleButton) findViewById(R.id.record_button);
    mRecordButton.setOnClickListener(mRecordButtonListener);

    mPlayButton = (AudioRecorderCircleButton) findViewById(R.id.play_button);
    mPlayButton.setOnClickListener(mPlayButtonListener);

    mDeleteButton = (AudioRecorderCircleButton) findViewById(R.id.delete_button);
    mDeleteButton.setOnClickListener(mDeleteButtonListener);

    mSaveButton = (AudioRecorderCircleButton) findViewById(R.id.save_button);
    mSaveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveAudio();
        }
    });

    // set up animation for the play/save buttons
    mRotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    mRotateAnimation.setDuration(BUTTON_ANIMATION_DURATION);
    mRotateAnimation.setInterpolator(new LinearInterpolator());
    mRotateAnimation.setRepeatCount(Animation.INFINITE);
    mRotateAnimation.setRepeatMode(Animation.RESTART);
}

From source file:github.daneren2005.dsub.activity.SubsonicActivity.java

@Override
protected void onCreate(Bundle bundle) {
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
        // tv = true;
    }//  www . j  a v  a 2  s.  c  o m
    PackageManager pm = getPackageManager();
    if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
        touchscreen = false;
    }

    setUncaughtExceptionHandler();
    applyTheme();
    applyFullscreen();
    super.onCreate(bundle);
    startService(new Intent(this, DownloadService.class));
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
        lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
    }

    if (preferencesListener == null) {
        preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
            @Override
            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
                // When changing drawer settings change visibility
                switch (key) {
                case Constants.PREFERENCES_KEY_PODCASTS_ENABLED:
                    setDrawerItemVisible(R.id.drawer_podcasts, false);
                    break;
                case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED:
                    setDrawerItemVisible(R.id.drawer_bookmarks, false);
                    break;
                case Constants.PREFERENCES_KEY_SHARED_ENABLED:
                    setDrawerItemVisible(R.id.drawer_shares, false);
                    break;
                case Constants.PREFERENCES_KEY_CHAT_ENABLED:
                    setDrawerItemVisible(R.id.drawer_chat, false);
                    break;
                case Constants.PREFERENCES_KEY_ADMIN_ENABLED:
                    setDrawerItemVisible(R.id.drawer_admin, false);
                    break;
                }
            }
        };
        Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
    }
}

From source file:com.Duo.music.player.NowPlayingActivity.NowPlayingActivity.java

@SuppressLint("NewApi")
@Override// w ww. jav a2 s  . co  m
protected void onCreate(Bundle savedInstanceState) {
    mContext = getApplicationContext();
    mApp = (Common) getApplicationContext();
    mApp.setNowPlayingActivity(this);
    setNowPlayingActivityListener(mApp.getPlaybackKickstarter());

    //Set the UI theme.
    setTheme();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_now_playing);

    //Set the volume stream for this activity.
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    //Drawer layout.
    if (!mApp.isTabletInLandscape()) {
        mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_drawer_root);
        mDrawerParentLayout = (FrameLayout) findViewById(R.id.now_playing_drawer_frame_root);
        mCurrentQueueLayout = (RelativeLayout) findViewById(R.id.queue_drawer);
        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setBackgroundColor(UIElementsHelper.getBackgroundColor(mContext));

    } else {
        mCurrentQueueLayout = (RelativeLayout) findViewById(R.id.queue_drawer);
    }

    //ViewPager.
    mViewPager = (VelocityViewPager) findViewById(R.id.nowPlayingPlaylistPager);

    //Seekbar indicator.
    mSeekbarIndicatorLayoutParent = (RelativeLayout) findViewById(R.id.seekbarIndicatorParent);
    mSeekbarIndicatorLayout = (RelativeLayout) findViewById(R.id.seekbarIndicator);
    mSeekbarIndicatorText = (TextView) findViewById(R.id.seekbarIndicatorText);

    mSeekbarIndicatorLayoutParent.setVisibility(View.GONE);
    mSeekbarIndicatorLayout.setBackgroundResource(UIElementsHelper.getGridViewCardBackground(mContext));
    mSeekbarIndicatorText.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    mSeekbarIndicatorText.setTextColor(UIElementsHelper.getThemeBasedTextColor(mContext));

    //Playback Controls.
    mControlsLayoutHeaderParent = (RelativeLayout) findViewById(R.id.now_playing_controls_header_parent);
    mControlsLayoutHeader = (RelativeLayout) findViewById(R.id.now_playing_controls_header);
    mPlayPauseButtonBackground = (RelativeLayout) findViewById(R.id.playPauseButtonBackground);
    mPlayPauseButton = (ImageButton) findViewById(R.id.playPauseButton);
    mNextButton = (ImageButton) findViewById(R.id.nextButton);
    mPreviousButton = (ImageButton) findViewById(R.id.previousButton);
    mShuffleButton = (ImageButton) findViewById(R.id.shuffleButton);
    mRepeatButton = (ImageButton) findViewById(R.id.repeatButton);

    //Song info/seekbar elements.
    mSeekbar = (SeekBar) findViewById(R.id.nowPlayingSeekBar);
    mStreamingProgressBar = (ProgressBar) findViewById(R.id.startingStreamProgressBar);
    mStreamingProgressBar.setVisibility(View.GONE);

    try {
        mSeekbar.setThumb(getResources().getDrawable(R.drawable.transparent_drawable));
    } catch (Exception e) {
        e.printStackTrace();
    }

    mPlayPauseButtonBackground.setBackgroundResource(UIElementsHelper.getShadowedCircle(mContext));
    mPlayPauseButton.setImageResource(R.drawable.pause_light);
    mPlayPauseButton.setId(R.drawable.pause_light);
    mNextButton.setImageResource(UIElementsHelper.getIcon(mContext, "btn_playback_next"));
    mPreviousButton.setImageResource(UIElementsHelper.getIcon(mContext, "btn_playback_previous"));

    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        mNextButton.setAlpha(1f);
        mPreviousButton.setAlpha(1f);
    }

    //KitKat specific layout code.
    setKitKatTranslucentBars();

    //Set the control buttons and background.
    setControlButtonsBackground();
    setPlayPauseButton();
    setShuffleButtonIcon();
    setRepeatButtonIcon();

    //Set the click listeners.
    mSeekbar.setOnSeekBarChangeListener(seekBarChangeListener);
    mNextButton.setOnClickListener(mOnClickNextListener);
    mPreviousButton.setOnClickListener(mOnClickPreviousListener);
    mPlayPauseButton.setOnClickListener(playPauseClickListener);
    mPlayPauseButtonBackground.setOnClickListener(playPauseClickListener);
    mShuffleButton.setOnClickListener(shuffleButtonClickListener);
    mRepeatButton.setOnClickListener(repeatButtonClickListener);

    //Apply haptic feedback to the play/pause button.
    mPlayPauseButtonBackground.setHapticFeedbackEnabled(true);
    mPlayPauseButton.setHapticFeedbackEnabled(true);

}

From source file:com.aniruddhc.acemusic.player.NowPlayingActivity.NowPlayingActivity.java

@SuppressLint("NewApi")
@Override/*from  www . j  a  v a 2s. c o m*/
protected void onCreate(Bundle savedInstanceState) {
    mContext = getApplicationContext();
    mApp = (Common) getApplicationContext();
    mApp.setNowPlayingActivity(this);
    setNowPlayingActivityListener(mApp.getPlaybackKickstarter());
    mFadeInAnimation = AnimationUtils.loadAnimation(mContext, R.anim.slide_in_from_top);
    mFadeInAnimation.setDuration(700);

    //Set the UI theme.
    setTheme();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_now_playing);

    //Set the volume stream for this activity.
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    //Drawer layout.
    if (!mApp.isTabletInLandscape()) {
        mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_drawer_root);
        mDrawerParentLayout = (FrameLayout) findViewById(R.id.now_playing_drawer_frame_root);
        mCurrentQueueLayout = (RelativeLayout) findViewById(R.id.queue_drawer);
        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setBackgroundColor(UIElementsHelper.getBackgroundColor(mContext));

    } else {
        mCurrentQueueLayout = (RelativeLayout) findViewById(R.id.queue_drawer);
    }

    //ViewPager.
    mViewPager = (VelocityViewPager) findViewById(R.id.nowPlayingPlaylistPager);

    //Seekbar indicator.
    mSeekbarIndicatorLayoutParent = (RelativeLayout) findViewById(R.id.seekbarIndicatorParent);
    mSeekbarIndicatorLayout = (RelativeLayout) findViewById(R.id.seekbarIndicator);
    mSeekbarIndicatorText = (TextView) findViewById(R.id.seekbarIndicatorText);

    mSeekbarIndicatorLayoutParent.setVisibility(View.GONE);
    mSeekbarIndicatorLayout.setBackgroundResource(UIElementsHelper.getGridViewCardBackground(mContext));
    mSeekbarIndicatorText.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    mSeekbarIndicatorText.setTextColor(UIElementsHelper.getThemeBasedTextColor(mContext));

    //Playback Controls.
    mControlsLayoutHeaderParent = (RelativeLayout) findViewById(R.id.now_playing_controls_header_parent);
    mControlsLayoutHeader = (RelativeLayout) findViewById(R.id.now_playing_controls_header);
    mPlayPauseButtonBackground = (RelativeLayout) findViewById(R.id.playPauseButtonBackground);
    mPlayPauseButton = (ImageButton) findViewById(R.id.playPauseButton);
    mNextButton = (ImageButton) findViewById(R.id.nextButton);
    mPreviousButton = (ImageButton) findViewById(R.id.previousButton);
    mShuffleButton = (ImageButton) findViewById(R.id.shuffleButton);
    mRepeatButton = (ImageButton) findViewById(R.id.repeatButton);

    //Song info/seekbar elements.
    mSeekbar = (SeekBar) findViewById(R.id.nowPlayingSeekBar);
    mStreamingProgressBar = (ProgressBar) findViewById(R.id.startingStreamProgressBar);
    mStreamingProgressBar.setVisibility(View.GONE);

    try {
        mSeekbar.setThumb(getResources().getDrawable(R.drawable.transparent_drawable));
    } catch (Exception e) {
        e.printStackTrace();
    }

    mPlayPauseButtonBackground.setBackgroundResource(UIElementsHelper.getShadowedCircle(mContext));
    mPlayPauseButton.setImageResource(R.drawable.pause_light);
    mPlayPauseButton.setId(R.drawable.pause_light);
    mNextButton.setImageResource(UIElementsHelper.getIcon(mContext, "btn_playback_next"));
    mPreviousButton.setImageResource(UIElementsHelper.getIcon(mContext, "btn_playback_previous"));

    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        mNextButton.setAlpha(1f);
        mPreviousButton.setAlpha(1f);
    }

    //KitKat specific layout code.
    setKitKatTranslucentBars();

    //Set the control buttons and background.
    setControlButtonsBackground();
    setPlayPauseButton();
    setShuffleButtonIcon();
    setRepeatButtonIcon();

    //Set the click listeners.
    mSeekbar.setOnSeekBarChangeListener(seekBarChangeListener);
    mNextButton.setOnClickListener(mOnClickNextListener);
    mPreviousButton.setOnClickListener(mOnClickPreviousListener);
    mPlayPauseButton.setOnClickListener(playPauseClickListener);
    mPlayPauseButtonBackground.setOnClickListener(playPauseClickListener);
    mShuffleButton.setOnClickListener(shuffleButtonClickListener);
    mRepeatButton.setOnClickListener(repeatButtonClickListener);

    //Apply haptic feedback to the play/pause button.
    mPlayPauseButtonBackground.setHapticFeedbackEnabled(true);
    mPlayPauseButton.setHapticFeedbackEnabled(true);

}

From source file:net.sourceforge.servestream.activity.MediaPlayerActivity.java

/** Called when the activity is first created. */
@Override//  www  .  ja v  a  2s .c o m
public void onCreate(Bundle icicle) {
    setTheme(UserPreferences.getTheme());
    super.onCreate(icicle);
    setContentView(R.layout.activity_media_player);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    //actionBar.setDisplayShowCustomEnabled(true);
    //actionBar.setDisplayShowTitleEnabled(false);

    LayoutInflater inflater = getLayoutInflater();
    View v = inflater.inflate(R.layout.action_bar_media_player_header, null);

    //actionBar.setCustomView(v);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    mCurrentTime = (TextView) findViewById(R.id.position_text);
    mTotalTime = (TextView) findViewById(R.id.duration_text);
    mProgress = (ProgressBar) findViewById(R.id.seek_bar);

    mPrevButton = (RepeatingImageButton) findViewById(R.id.previous_button);
    mPrevButton.setOnClickListener(mPrevListener);
    mPrevButton.setRepeatListener(mRewListener, 260);
    mPauseButton = (ImageButton) findViewById(R.id.play_pause_button);
    mPauseButton.setOnClickListener(mPauseListener);
    mNextButton = (RepeatingImageButton) findViewById(R.id.next_button);
    mNextButton.setOnClickListener(mNextListener);
    mNextButton.setRepeatListener(mFfwdListener, 260);
    seekmethod = 1;

    mDeviceHasDpad = (getResources().getConfiguration().navigation == Configuration.NAVIGATION_DPAD);

    mShuffleButton = (ImageButton) findViewById(R.id.shuffle_button);
    mShuffleButton.setOnClickListener(mShuffleListener);
    mRepeatButton = (ImageButton) findViewById(R.id.repeat_button);
    mRepeatButton.setOnClickListener(mRepeatListener);

    if (mProgress instanceof SeekBar) {
        SeekBar seeker = (SeekBar) mProgress;
        seeker.setOnSeekBarChangeListener(mSeekListener);
    }
    mProgress.setMax(1000);

    mPager = (ViewPager) findViewById(R.id.pager);
}