List of usage examples for android.media AudioManager AUDIOFOCUS_GAIN
int AUDIOFOCUS_GAIN
To view the source code for android.media AudioManager AUDIOFOCUS_GAIN.
Click Source Link
From source file:com.av.remusic.service.MediaService.java
public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D)/*ww w . j ava 2 s. co m*/ Log.d(TAG, "Starting playback: audio focus request status = " + status); if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { return; } final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mSession.setActive(true); if (createNewNextTrack) { setNextTrack(); } else { setNextTrack(mNextPlayPos); } if (mPlayer.isTrackPrepared()) { final long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } } mPlayer.start(); mPlayerHandler.removeMessages(FADEDOWN); mPlayerHandler.sendEmptyMessage(FADEUP); setIsSupposedToBePlaying(true, true); cancelShutdown(); updateNotification(); notifyChange(META_CHANGED); }
From source file:com.cyanogenmod.eleven.MusicPlaybackService.java
/** * Resumes or starts playback.// www . ja v a 2 s .c o m * * @param createNewNextTrack True if you want to figure out the next track, false * if you want to re-use the existing next track (used for going back) */ public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D) Log.d(TAG, "Starting playback: audio focus request status = " + status); if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { return; } final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); mSession.setActive(true); if (createNewNextTrack) { setNextTrack(); } else { setNextTrack(mNextPlayPos); } if (mPlayer.isInitialized()) { final long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } mPlayer.start(); mPlayerHandler.removeMessages(FADEDOWN); mPlayerHandler.sendEmptyMessage(FADEUP); setIsSupposedToBePlaying(true, true); cancelShutdown(); updateNotification(); } else if (mPlaylist.size() <= 0) { setShuffleMode(SHUFFLE_AUTO); } }