David Prun
David Prun

Reputation: 8453

Unable to Resume Android default music player

I am trying to pause any music that is already playing in the Android device that uses default music player. I went over Android doc http://developer.android.com/training/managing-audio/audio-focus.html . I can pause music when I want, but I am not able to resume the previously paused music after my work is done, although I use am.abandonAudioFocus(afChangeListener);

      AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);


        // Request audio focus for playback
        int result = am.requestAudioFocus(mAudioFocusListener,
                                         // Use the music stream.
                                         AudioManager.STREAM_MUSIC,
                                         // Request permanent focus.
                                         AudioManager.AUDIOFOCUS_GAIN);

        if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

                mPlayer.start();
        }

Once my tone stops I call am.abandonAudioFocus(mAudioFocusListener) and unable to achieve this.

Upvotes: 2

Views: 761

Answers (1)

Jayesh Tembhekar
Jayesh Tembhekar

Reputation: 526

Instead of using AudioManager.AUDIOFOCUS_GAIN try AudioManager.AUDIOFOCUS_GAIN_TRANSIENT.

Upvotes: 4

Related Questions