Example usage for android.media.audiofx AudioEffect ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION

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

Introduction

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

Prototype

String ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION

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

Click Source Link

Document

Intent to signal to the effect control application or service that an audio session is closed and that effects should not be applied anymore.

Usage

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

@Override
public void onDestroy() {
    if (D)/*from   ww w  .j  a v a2s  .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  ww  w .j  av  a 2s .com
    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:singh.amandeep.musicplayer.MusicService.java

/**
 * {@inheritDoc}//from  w w w  . j  a  va2 s. c om
 */
@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();
}

From source file:com.andrew.apollo.MusicPlaybackService.java

/**
 * {@inheritDoc}/*from  ww w. j  av a2 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}// ww  w.ja  va  2 s  .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.rks.musicx.services.MusicXService.java

@Override
public void onDestroy() {
    super.onDestroy();
    Extras.getInstance().setwidgetPosition(100);
    audioWidget.cleanUp();/* w w  w. j  a v a  2 s  .  c om*/
    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.devalladolid.musictoday.MusicService.java

public void pause() {
    if (D)/*from  w  ww  . j av a2  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);
        }
    }
}

From source file:com.naman14.timber.musicplayer.MusicService.java

public void pause() {
    if (D) {/*from  w w w. jav  a 2 s.  com*/
        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 pause() {
    if (D)/*from   w ww. j a  v 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);
            stopShakeDetector(false);
        }
    }
}

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

/**
 * Temporarily pauses playback.//from  w  w  w .j ava  2s .c  o  m
 */
public void pause() {
    if (mPlayerHandler == null)
        return;
    LogUtils.d(TAG, "Pausing playback");
    synchronized (this) {
        if (mPlayerHandler != null) {
            mPlayerHandler.removeMessages(MusicServiceConstants.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);

            if (mPlayer != null) {
                mPlayer.pause();
            }
            setIsSupposedToBePlaying(false, true);
            stopShakeDetector(false);
        }
    }
}