3

I have a video without any audio playing in my activity, so if my music player is playing and my app is opened the music stops. I was wondering if there is a way to not request the Audio focus and let the music play in the background even when my video is playing ? I have tried abandoning audio focus after starting the video but that doesn't seem to work either.

Here's the code I have tried till now -

    String path = "android.resource://" + getPackageName() + "/" + R.raw.backgroundvideo;
    mvvBackground.setVideoURI(Uri.parse(path));
    mvvBackground.setMediaController(null);
    mvvBackground.start();
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    am.abandonAudioFocus(new AudioManager.OnAudioFocusChangeListener() {
        @Override
        public void onAudioFocusChange(int focusChange) {

             Log.d(LOG_TAG, "Audio focus changed!");

        }
    });

Any suggestions will be appreciated ! Thanks

Adnan Mulla
  • 2,872
  • 3
  • 25
  • 35
  • Check this - http://stackoverflow.com/questions/28119955/disable-androids-videoview-requestaudiofocus-when-playing-a-video – random Apr 09 '15 at 07:21

1 Answers1

1

I have not tried this, but according to the docs, for API level 26 and above you can use mVideoView.setAudioFocusRequest(AudioManager.AUDIOFOCUS_NONE) to achieve this behaviour.

For below that API level, there is a workaround mentioned here.

Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35