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:github.daneren2005.dsub.service.DownloadServiceImpl.java

@Override
public void onDestroy() {
    super.onDestroy();
    instance = null;/*  www  .  j a v a2s .  com*/

    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, mediaPlayer.getAudioSessionId());
        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();
    if (equalizerController != null) {
        equalizerController.release();
    }
    if (visualizerController != null) {
        visualizerController.release();
    }
    if (mRemoteControl != null) {
        mRemoteControl.unregister(this);
        mRemoteControl = null;
    }

    if (bufferTask != null) {
        bufferTask.cancel();
    }
    if (nextPlayingTask != null) {
        nextPlayingTask.cancel();
    }
    Util.hidePlayingNotification(this, this, handler);
}

From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java

@Override
public void onDestroy() {
    super.onDestroy();

    try {//from w ww  .j a v  a  2s  .com
        instance = null;
        lifecycleSupport.onDestroy();
        mediaPlayer.release();

        if (nextMediaPlayer != null) {
            nextMediaPlayer.release();
        }

        mediaPlayerLooper.quit();
        shufflePlayBuffer.shutdown();

        if (equalizerController != null) {
            equalizerController.release();
        }

        if (visualizerController != null) {
            visualizerController.release();
        }

        if (bufferTask != null) {
            bufferTask.cancel();
        }

        if (nextPlayingTask != null) {
            nextPlayingTask.cancel();
        }

        Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
        i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
        i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
        sendBroadcast(i);

        audioManager.unregisterRemoteControlClient(remoteControlClient);
        clearRemoteControl();

        wakeLock.release();
    } catch (Throwable ignored) {
    }
}

From source file:github.daneren2005.dsub.service.DownloadService.java

@Override
public void onDestroy() {
    super.onDestroy();
    instance = null;/* www . ja  v a2 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;
    }
    mediaRouter.destroy();
    Notifications.hidePlayingNotification(this, this, handler);
    Notifications.hideDownloadingNotification(this, this, handler);
}

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

@Override
public void onDestroy() {
    if (D)/*from  w  w  w .j  a  v a 2 s . c om*/
        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:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java

@Override
public void onDestroy() {
    // Check that we're not being destroyed while something is still playing.
    if (isPlaying()) {
        Log.e(LOGTAG, "Service being destroyed while still playing.");
    }/*from   www .j  a  v a2s . c o m*/
    // 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);
    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;
    }

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

From source file:com.techmighty.baseplayer.MusicService.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);

    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}//w  w w . ja va2s.  co 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;//  w  w  w. j a  v a  2s.c om

    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   w ww  .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.bluros.music.MusicService.java

@Override
public void onDestroy() {
    if (D)/*from   ww  w  .  jav 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);

    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();
}