List of usage examples for android.media AudioManager abandonAudioFocus
public int abandonAudioFocus(OnAudioFocusChangeListener l)
From source file:com.evandroid.musica.MainLyricActivity.java
@SuppressLint("InlinedApi") public void resync(MenuItem item) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.requestAudioFocus(null,/*from w ww . jav a 2s . com*/ // Use the music stream. AudioManager.STREAM_SYSTEM, // Request permanent focus. AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); am.abandonAudioFocus(null); }
From source file:com.yohpapa.research.simplemusicplayer.PlaybackService.java
private void abandonAudioFocus() { AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE); manager.abandonAudioFocus(onAudioFocusChangeListener); }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
private void nativeRingtone(Context context, boolean hasSound) { if (hasSound) { final AudioManager.OnAudioFocusChangeListener listener = this; final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(listener, AudioManager.STREAM_NOTIFICATION, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mRingtone = RingtoneManager.getRingtone(context, notification); mRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); mRingtone.play();/*from www . j a va2 s . c om*/ final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { audioManager.abandonAudioFocus(listener); } }, AUDIO_FOCUS_DURATION); } } }
From source file:com.xnxs.mediaplayer.widget.media.VRVideoView.java
public void release(boolean cleartargetstate) { if (mMediaPlayer != null) { mMediaPlayer.reset();/*from ww w . j a v a 2 s .c o m*/ mMediaPlayer.release(); mMediaPlayer = null; // REMOVED: mPendingSubtitleTracks.clear(); mCurrentState = STATE_IDLE; if (cleartargetstate) { mTargetState = STATE_IDLE; } AudioManager am = getAudioManager(); am.abandonAudioFocus(null); } }
From source file:org.videolan.vlc.AudioService.java
@TargetApi(8) private void changeAudioFocus(boolean gain) { if (!Util.isFroyoOrLater()) // NOP if not supported return;//from ww w .j a v a 2 s . c om audioFocusListener = new OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) { /* * Lower the volume to 36% to "duck" when an alert or something * needs to be played. */ LibVLC.getExistingInstance().setVolume(36); } else { LibVLC.getExistingInstance().setVolume(100); } } }; AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (gain) am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); else am.abandonAudioFocus(audioFocusListener); }
From source file:org.videolan.myvlc.core.mediaController.AudioService.java
@TargetApi(Build.VERSION_CODES.FROYO) private void changeAudioFocus(boolean gain) { if (!Util.isFroyoOrLater()) // NOP if not supported return;/*from w w w . j a va2 s .c o m*/ audioFocusListener = new OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) { /* * Lower the volume to 36% to "duck" when an alert or something * needs to be played. */ //LibVLC.getExistingInstance().setVolume(36); } else { //LibVLC.getExistingInstance().setVolume(100); } } }; AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (gain) am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); else am.abandonAudioFocus(audioFocusListener); }
From source file:org.videolan.vlc.MediaService.java
@TargetApi(8) private void changeAudioFocus(boolean gain) { if (!Util.isFroyoOrLater()) // NOP if not supported return;/* w ww. jav a 2s . co m*/ if (audioFocusListener == null) { audioFocusListener = new OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { switch (focusChange) { case AudioManager.AUDIOFOCUS_LOSS: if (LibVLC.getExistingInstance().isPlaying()) { stop(); } break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: if (LibVLC.getExistingInstance().isPlaying()) { pause(); } break; case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: LibVLC.getExistingInstance().setVolume(36); break; case AudioManager.AUDIOFOCUS_GAIN: case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: LibVLC.getExistingInstance().setVolume(100); break; default: break; } } }; } Log.i(TAG, "changeAudioFocus gain=" + gain); AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (gain) am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); else am.abandonAudioFocus(audioFocusListener); }
From source file:com.yamin.kk.service.AudioService.java
@TargetApi(Build.VERSION_CODES.FROYO) private void changeAudioFocus(boolean gain) { if (!Util.isFroyoOrLater()) // NOP if not supported return;// w w w. j ava 2 s.c o m audioFocusListener = new OnAudioFocusChangeListener() { @Override public void onAudioFocusChange(int focusChange) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) { /* * Lower the volume to 36% to "duck" when an alert or something * needs to be played. */ LibVLC.getExistingInstance().setVolume(36); } else { LibVLC.getExistingInstance().setVolume(100); } } }; AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (gain) am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); else am.abandonAudioFocus(audioFocusListener); }
From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java
public void stopPlayback() { if (mMediaPlayer != null) { mMediaPlayer.stop();//from w w w . ja va 2s .c o m mMediaPlayer.release(); mMediaPlayer = null; if (mHudViewHolder != null) mHudViewHolder.setMediaPlayer(null); mCurrentState = STATE_IDLE; mTargetState = STATE_IDLE; AudioManager am = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE); am.abandonAudioFocus(null); } }
From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java
public void release(boolean cleartargetstate) { if (mMediaPlayer != null) { mMediaPlayer.reset();//from w ww. j a va2 s . c om mMediaPlayer.release(); mMediaPlayer = null; // REMOVED: mPendingSubtitleTracks.clear(); mCurrentState = STATE_IDLE; if (cleartargetstate) { mTargetState = STATE_IDLE; } AudioManager am = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE); am.abandonAudioFocus(null); } }