Java Code Examples for android.media.audiofx.AudioEffect#ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION

The following examples show how to use android.media.audiofx.AudioEffect#ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicService.java    From Muzesto with GNU General Public License v3.0 6 votes vote down vote up
public void pause() {
    if (D) 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);
        }
    }
}
 
Example 2
Source File: EqualizerFragment.java    From Bop with Apache License 2.0 5 votes vote down vote up
private  void unbindSystemEqualizer(int audioSessionId) {
    Context c = getContext();
    Intent intent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
    intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, c.getPackageName());
    c.sendBroadcast(intent);
}
 
Example 3
Source File: MusicService.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
@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);


    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();
}
 
Example 4
Source File: DownloadService.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    instance = null;

    if (currentPlaying != null) currentPlaying.setPlaying(false);
    lifecycleSupport.onDestroy();

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

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

    if (bufferTask != null) {
        bufferTask.cancel();
        bufferTask = null;
    }
    if (nextPlayingTask != null) {
        nextPlayingTask.cancel();
        nextPlayingTask = null;
    }
    if (proxy != null) {
        proxy.stop();
        proxy = null;
    }
    Notifications.hidePlayingNotification(this, this, handler);
    Notifications.hideDownloadingNotification(this, this, handler);

    unregisterReceiver(audioNoisyReceiver);
}
 
Example 5
Source File: ApolloService.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void onDestroy() {
    // Check that we're not being destroyed while something is still
    // playing.
    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);
    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();
}
 
Example 6
Source File: GaplessPlayer.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Stops media playback
 */
synchronized void stop() {
    stopReleaseTask();
    // Check if a player exists otherwise there is nothing to do.
    if (mCurrentMediaPlayer != null) {
        // Check if the player for the next song exists already
        if (mNextMediaPlayer != null) {
            // Remove the next player from the currently playing one.
            mCurrentMediaPlayer.setNextMediaPlayer(null);
            // Release the MediaPlayer, not usable after this command
            mNextMediaPlayer.release();

            // Reset variables to clean internal state
            mNextMediaPlayer = null;
            mSecondPrepared = false;
            mSecondPreparing = false;
        }

        // Check if the currently active player is ready
        if (mCurrentPrepared) {
            /*
             * Signal android desire to close audio effect session
             */
            Intent audioEffectIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
            audioEffectIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mCurrentMediaPlayer.getAudioSessionId());
            audioEffectIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, mPlaybackService.getPackageName());
            mPlaybackService.sendBroadcast(audioEffectIntent);

            if (BuildConfig.DEBUG) {
                Log.v(TAG, "Closing effect for session: " + mCurrentMediaPlayer.getAudioSessionId());
            }
        }
        // Release the current player
        mCurrentMediaPlayer.release();

        // Reset variables to clean internal state
        mCurrentMediaPlayer = null;
        mCurrentPrepared = false;
    }
}
 
Example 7
Source File: MediaPlaybackService.java    From coursera-android with MIT License 5 votes vote down vote up
@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.");
    }
    // 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();
}
 
Example 8
Source File: PlayerService.java    From misound with Apache License 2.0 5 votes vote down vote up
@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.");
    }
    // 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();
    mWorker.quit();
    super.onDestroy();
}
 
Example 9
Source File: MusicService.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
private void closeAudioEffectSession() {
    final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(audioEffectsIntent);
}
 
Example 10
Source File: MusicService.java    From MusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void closeAudioEffectSession() {
    final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(audioEffectsIntent);
}
 
Example 11
Source File: MusicService.java    From Orin with GNU General Public License v3.0 4 votes vote down vote up
private void closeAudioEffectSession() {
    final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(audioEffectsIntent);
}
 
Example 12
Source File: MusicService.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void closeAudioEffectSession() {
    final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(audioEffectsIntent);
}
 
Example 13
Source File: MusicService.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
private void closeAudioEffectSession() {
    final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(audioEffectsIntent);
}
 
Example 14
Source File: MusicService.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
private void closeAudioEffectSession() {
    final Intent audioEffectsIntent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, playback.getAudioSessionId());
    audioEffectsIntent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(audioEffectsIntent);
}
 
Example 15
Source File: EqualizedExoPlayer.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private void unbindSystemEqualizer(int audioSessionId) {
    Intent intent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
    intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
    intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, mContext.getPackageName());
    mContext.sendBroadcast(intent);
}
 
Example 16
Source File: DownloadService.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDestroy() {
	super.onDestroy();
	instance = null;

	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();
	if (Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, true)
			&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
		stopForeground(android.app.Service.STOP_FOREGROUND_DETACH);
	} else {
		Notifications.hidePlayingNotification(this, this, handler);
	}
	Notifications.hideDownloadingNotification(this, this, handler);
}