Example usage for android.media.audiofx AudioEffect EXTRA_AUDIO_SESSION

List of usage examples for android.media.audiofx AudioEffect EXTRA_AUDIO_SESSION

Introduction

In this page you can find the example usage for android.media.audiofx AudioEffect EXTRA_AUDIO_SESSION.

Prototype

String EXTRA_AUDIO_SESSION

To view the source code for android.media.audiofx AudioEffect EXTRA_AUDIO_SESSION.

Click Source Link

Document

Contains the ID of the audio session the effects should be applied to.

Usage

From source file:com.techmighty.baseplayer.MusicService.java

@Override
public void onDestroy() {
    if (D)//  ww w. j  a  v  a2 s .co m
        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);

    mAlarmManager.cancel(mShutdownIntent);

    mPlayerHandler.removeCallbacksAndMessages(null);

    if (BasePlayerUtils.isJellyBeanMR2())
        mHandlerThread.quitSafely();
    else
        mHandlerThread.quit();

    mPlayer.release();
    mPlayer = null;

    mAudioManager.abandonAudioFocus(mAudioFocusListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mSession.release();

    getContentResolver().unregisterContentObserver(mMediaStoreObserver);

    closeCursor();

    unregisterReceiver(mIntentReceiver);
    if (mUnmountReceiver != null) {
        unregisterReceiver(mUnmountReceiver);
        mUnmountReceiver = null;
    }

    mWakeLock.release();
}

From source file:com.koma.music.service.MusicService.java

/**
 * {@inheritDoc}//from   w ww  . ja  v  a2 s. c  o  m
 */
@Override
public void onDestroy() {
    LogUtils.d(TAG, "Destroying service");
    if (!mReadGranted) {
        return;
    }
    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(mMediaObserver);

    // 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:github.popeen.dsub.service.DownloadService.java

@Override
public void onDestroy() {
    super.onDestroy();
    instance = null;//from  ww w  .j  a  v a 2  s .  c o m

    if (currentPlaying != null)
        currentPlaying.setPlaying(false);
    if (sleepTimer != null) {
        sleepTimer.cancel();
        sleepTimer.purge();
    }
    lifecycleSupport.onDestroy();

    try {
        Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
        i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
        i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
        sendBroadcast(i);
    } catch (Throwable e) {
        // Froyo or lower
    }

    mediaPlayer.release();
    if (nextMediaPlayer != null) {
        nextMediaPlayer.release();
    }
    mediaPlayerLooper.quit();
    shufflePlayBuffer.shutdown();
    effectsController.release();
    if (mRemoteControl != null) {
        mRemoteControl.unregister(this);
        mRemoteControl = null;
    }

    if (bufferTask != null) {
        bufferTask.cancel();
        bufferTask = null;
    }
    if (nextPlayingTask != null) {
        nextPlayingTask.cancel();
        nextPlayingTask = null;
    }
    if (remoteController != null) {
        remoteController.stop();
        remoteController.shutdown();
    }
    if (proxy != null) {
        proxy.stop();
        proxy = null;
    }
    if (audioNoisyReceiver != null) {
        unregisterReceiver(audioNoisyReceiver);
    }
    mediaRouter.destroy();
    Notifications.hidePlayingNotification(this, this, handler);
    Notifications.hideDownloadingNotification(this, this, handler);
}

From source file:com.devalladolid.musictoday.MusicService.java

@Override
public void onDestroy() {
    if (D)/*from   ww w  . j  a va 2 s  .  co  m*/
        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);

    mAlarmManager.cancel(mShutdownIntent);

    mPlayerHandler.removeCallbacksAndMessages(null);

    if (TimberUtils.isJellyBeanMR2())
        mHandlerThread.quitSafely();
    else
        mHandlerThread.quit();

    mPlayer.release();
    mPlayer = null;

    mAudioManager.abandonAudioFocus(mAudioFocusListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mSession.release();

    getContentResolver().unregisterContentObserver(mMediaStoreObserver);

    closeCursor();

    unregisterReceiver(mIntentReceiver);
    if (mUnmountReceiver != null) {
        unregisterReceiver(mUnmountReceiver);
        mUnmountReceiver = null;
    }

    mWakeLock.release();
}

From source file:com.rks.musicx.ui.activities.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == OVERLAY_REQ) {
        if (Build.VERSION.SDK_INT >= M) {
            if (Settings.canDrawOverlays(this)) {
                Log.d("MainActivity", "Granted");
            } else {
                Extras.getInstance().setWidgetTrack(true);
                Log.d("MainActivity", "Denied or Grant permission Manually");
            }/*w ww. j av a  2  s.  c o m*/
        }
    }
    if (requestCode == WRITESETTINGS) {
        if (Build.VERSION.SDK_INT >= M) {
            if (!Settings.System.canWrite(this)) {
                Log.d("MainActivity", "Granted");
            } else {
                Extras.getInstance().setSettings(true);
                Log.d("MainActivity", "Denied or Grant permission Manually");
            }
        }
    }
    if (requestCode == EQ) {
        Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
        if (intent.getAction() != null && Helper.isActivityPresent(MainActivity.this, intent)) {
            if (musicXService == null) {
                return;
            }
            intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, musicXService.audioSession());
            intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, this.getPackageName());
            intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
            sendBroadcast(intent);
        } else {
            Log.d("MainActivity", "Error");
        }
    }
    if (requestCode == NAV && resultCode == RESULT_OK) {
        intent = data;
    }
}

From source file:com.bluros.music.MusicService.java

@Override
public void onDestroy() {
    if (D)//  ww w. j ava2  s  . c  o m
        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);

    mAlarmManager.cancel(mShutdownIntent);

    mPlayerHandler.removeCallbacksAndMessages(null);

    if (MusicUtils.isJellyBeanMR2())
        mHandlerThread.quitSafely();
    else
        mHandlerThread.quit();

    mPlayer.release();
    mPlayer = null;

    mAudioManager.abandonAudioFocus(mAudioFocusListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mSession.release();

    getContentResolver().unregisterContentObserver(mMediaStoreObserver);

    closeCursor();

    unregisterReceiver(mIntentReceiver);
    if (mUnmountReceiver != null) {
        unregisterReceiver(mUnmountReceiver);
        mUnmountReceiver = null;
    }

    stopShakeDetector(true);

    mWakeLock.release();
}

From source file:com.av.remusic.service.MediaService.java

@Override
public void onDestroy() {
    if (D)/*  w  w  w .  j  a v  a 2  s. c  o  m*/
        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);

    cancelNotification();

    mAlarmManager.cancel(mShutdownIntent);

    mPlayerHandler.removeCallbacksAndMessages(null);

    if (CommonUtils.isJellyBeanMR2())
        mHandlerThread.quitSafely();
    else
        mHandlerThread.quit();

    mPlayer.release();
    mPlayer = null;

    mAudioManager.abandonAudioFocus(mAudioFocusListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mSession.release();

    getContentResolver().unregisterContentObserver(mMediaStoreObserver);

    closeCursor();

    unregisterReceiver(mIntentReceiver);
    if (mUnmountReceiver != null) {
        unregisterReceiver(mUnmountReceiver);
        mUnmountReceiver = null;
    }

    mWakeLock.release();
}

From source file:com.andrew.apolloMod.service.ApolloService.java

@Override
public void onDestroy() {
    // Check that we're not being destroyed while something is still
    // playing./*from   www .j a  v  a  2 s. c o m*/
    if (mIsSupposedToBePlaying) {
        Log.e(LOGTAG, "Service being destroyed while still playing.");
    }
    // release all MediaPlayer resources, including the native player and
    // wakelocks
    Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
    i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(i);
    mPlayer.release();
    mPlayer = null;

    mAudioManager.abandonAudioFocus(mAudioFocusListener);

    if (Constants.isApi14Supported()) {
        mAudioManager.unregisterRemoteControlClient(mRemoteControlClient);
    }

    // make sure there aren't any other messages coming
    mDelayedStopHandler.removeCallbacksAndMessages(null);
    mMediaplayerHandler.removeCallbacksAndMessages(null);

    if (mCursor != null) {
        mCursor.close();
        mCursor = null;
    }
    updateAlbumBitmap();

    unregisterReceiver(mIntentReceiver);
    if (mUnmountReceiver != null) {
        unregisterReceiver(mUnmountReceiver);
        mUnmountReceiver = null;
    }
    mWakeLock.release();
    super.onDestroy();
}

From source file:com.android.music.MediaPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    badSymptoms.saveMenu("menu", item.toString());

    Intent intent;//from  w  w  w.j av  a 2  s.  c  om
    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:singh.amandeep.musicplayer.MusicService.java

/**
 * {@inheritDoc}/* w w  w . j  a v a 2  s.c  o m*/
 */
@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;
    }

    // Release the wake lock
    mWakeLock.release();
}