List of usage examples for android.media.audiofx AudioEffect EXTRA_AUDIO_SESSION
String EXTRA_AUDIO_SESSION
To view the source code for android.media.audiofx AudioEffect EXTRA_AUDIO_SESSION.
Click Source Link
From source file:com.andrew.apollo.MusicPlaybackService.java
/** * {@inheritDoc}/*from ww w. ja v a 2 s.c o m*/ */ @Override public void onDestroy() { if (D) LOG.info("Destroying service"); super.onDestroy(); // Tell any sound effect processors (e.g. equalizers) that we're leaving try { final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(audioEffectsIntent); } catch (Throwable ignored) { } // remove any pending alarms // note: mShutdownIntent could be null because during creation // internally PendingIntent.getService is eating (and ignoring) // a possible RemoteException if (mAlarmManager != null && mShutdownIntent != null) { mAlarmManager.cancel(mShutdownIntent); } // Remove all pending messages before kill the player if (mPlayerHandler != null) { mPlayerHandler.removeCallbacksAndMessages(null); } // Release the player if (mPlayer != null) { mPlayer.release(); mPlayer = null; } // Release simple player if (mSimplePlayer != null) { mSimplePlayer.release(); mSimplePlayer = null; } // Remove the audio focus listener and lock screen controls if (mAudioManager != null) { mAudioManager.abandonAudioFocus(mAudioFocusListener); mAudioManager.unregisterRemoteControlClient(mRemoteControlClient); } // Remove any callbacks from the handler if (mPlayerHandler != null) { mPlayerHandler.removeCallbacksAndMessages(null); mPlayerHandler.getLooper().quit(); } // Close the cursor closeCursor(); // Unregister the mount listener try { unregisterReceiver(mIntentReceiver); } catch (Throwable ignored) { } if (mUnmountReceiver != null) { try { unregisterReceiver(mUnmountReceiver); } catch (Throwable ignored) { } mUnmountReceiver = null; } // Release the wake lock if (mWakeLock != null) { try { mWakeLock.release(); } catch (RuntimeException ignored) { // might be underlocked and otherwise causing a crash on shutdown } } }
From source file:com.cyanogenmod.eleven.MusicPlaybackService.java
/** * {@inheritDoc}/*from w w w . j ava 2s . com*/ */ @Override public void onDestroy() { if (D) Log.d(TAG, "Destroying service"); super.onDestroy(); // Remove any sound effects final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(audioEffectsIntent); // remove any pending alarms mAlarmManager.cancel(mShutdownIntent); // Remove any callbacks from the handler mPlayerHandler.removeCallbacksAndMessages(null); // quit the thread so that anything that gets posted won't run mHandlerThread.quitSafely(); // Release the player mPlayer.release(); mPlayer = null; // Remove the audio focus listener and lock screen controls mAudioManager.abandonAudioFocus(mAudioFocusListener); mSession.release(); // remove the media store observer getContentResolver().unregisterContentObserver(mMediaStoreObserver); // Close the cursor closeCursor(); // Unregister the mount listener unregisterReceiver(mIntentReceiver); if (mUnmountReceiver != null) { unregisterReceiver(mUnmountReceiver); mUnmountReceiver = null; } // deinitialize shake detector stopShakeDetector(true); }
From source file:com.android.app.MediaPlaybackActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent;//ww w . ja v a 2 s . co m try { switch (item.getItemId()) { case GOTO_START: intent = new Intent(); intent.setClass(this, MusicBrowserActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); break; case USE_AS_RINGTONE: { // Set the system setting to make this the current ringtone if (mService != null) { MusicUtils.setRingtone(this, mService.getAudioId()); } return true; } case PARTY_SHUFFLE: MusicUtils.togglePartyShuffle(); setShuffleButtonImage(); break; case NEW_PLAYLIST: { intent = new Intent(); intent.setClass(this, CreatePlaylist.class); startActivityForResult(intent, NEW_PLAYLIST); return true; } case PLAYLIST_SELECTED: { long[] list = new long[1]; list[0] = MusicUtils.getCurrentAudioId(); long playlist = item.getIntent().getLongExtra("playlist", 0); MusicUtils.addToPlaylist(this, list, playlist); return true; } case DELETE_ITEM: { if (mService != null) { long[] list = new long[1]; list[0] = MusicUtils.getCurrentAudioId(); Bundle b = new Bundle(); String f; if (android.os.Environment.isExternalStorageRemovable()) { f = getString(R.string.delete_song_desc, mService.getTrackName()); } else { f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName()); } b.putString("description", f); b.putLongArray("items", list); intent = new Intent(); intent.setClass(this, DeleteItems.class); intent.putExtras(b); startActivityForResult(intent, -1); } return true; } case EFFECTS_PANEL: { Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mService.getAudioSessionId()); startActivityForResult(i, EFFECTS_PANEL); return true; } } } catch (RemoteException ex) { } return super.onOptionsItemSelected(item); }
From source file:com.rks.musicx.services.MusicXService.java
@Override public void onDestroy() { super.onDestroy(); Extras.getInstance().setwidgetPosition(100); audioWidget.cleanUp();//from w ww .j av a2s . co m audioWidget = null; Equalizers.EndEq(); BassBoosts.EndBass(); Virtualizers.EndVirtual(); Loud.EndLoudnessEnhancer(); Reverb.EndReverb(); receiverCleanup(); Extras.getInstance().eqSwitch(false); audioManager.abandonAudioFocus(this); removeProgress(); fastplay = false; isPlaying = false; paused = false; stopMediaplayer(); if (!Extras.getInstance().hideLockscreen()) { if (mediaSessionLockscreen != null) { mediaSessionLockscreen.release(); mediaSessionLockscreen = null; } } Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); if (Helper.isActivityPresent(this, i)) { i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSession()); i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, this.getPackageName()); sendBroadcast(i); } else { Log.d(TAG, "no activity found"); } if (!Extras.getInstance().hideNotify()) { removeNotification(); } }
From source file:com.example.chu.myvideodemo.MusicService.java
public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D)/* w w w. j a v a 2s. c om*/ 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.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(); notifyChange(META_CHANGED); } else if (mPlaylist.size() <= 0) { setShuffleMode(SHUFFLE_AUTO); } }
From source file:com.devalladolid.musictoday.MusicService.java
public void pause() { if (D)//from w ww .j a va 2 s . c om Log.d(TAG, "Pausing playback"); synchronized (this) { mPlayerHandler.removeMessages(FADEUP); if (mIsSupposedToBePlaying) { final Intent intent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mPlayer.pause(); notifyChange(META_CHANGED); setIsSupposedToBePlaying(false, true); } } }
From source file:com.naman14.timber.musicplayer.MusicService.java
public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D) {/* w w w .java 2 s . c om*/ 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.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(); notifyChange(META_CHANGED); } else if (mPlaylist.size() <= 0) { setShuffleMode(SHUFFLE_AUTO); } }
From source file:com.naman14.timber.musicplayer.MusicService.java
public void pause() { if (D) {/*from ww w .j av a 2 s . co m*/ Log.d(TAG, "Pausing playback"); } synchronized (this) { mPlayerHandler.removeMessages(FADEUP); if (mIsSupposedToBePlaying) { final Intent intent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mPlayer.pause(); notifyChange(META_CHANGED); setIsSupposedToBePlaying(false, true); } } }
From source file:com.bluros.music.MusicService.java
public void play(boolean createNewNextTrack) { int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D)//from w w w .j a v a 2 s.c om 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.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(); notifyChange(META_CHANGED); } else if (mPlaylist.size() <= 0) { setShuffleMode(SHUFFLE_AUTO); } }
From source file:com.bluros.music.MusicService.java
public void pause() { if (D)/* w ww .ja va 2 s.c o m*/ Log.d(TAG, "Pausing playback"); synchronized (this) { mPlayerHandler.removeMessages(FADEUP); if (mIsSupposedToBePlaying) { final Intent intent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId()); intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(intent); mPlayer.pause(); notifyChange(META_CHANGED); setIsSupposedToBePlaying(false, true); stopShakeDetector(false); } } }