I'd like to ask you about Audio Focus.

Asked 2 years ago, Updated 2 years ago, 21 views

Hello.

I'm always grateful for your help.

It's nothing but I'm re-imaging videos using VideoView

The problem is that while listening to music, apps such as (melon or genie) stop or turn off.

I don't want to shut down music listening apps even if the re-app is running. (For your information, our videos are voiceless.))

So I looked it up a little and found something called Audio Focus, and I wonder if there is a solution.

android

2022-09-21 17:59

1 Answers

Calling the setVideoURI() function in VideoView calls openVideo() internally.

private void openVideo() {
    ...

    AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    ...
}

Music playback in other music apps is stopped because the audio focus is requested inside the openVideo(). As a result of testing, VideoView has not found a solution to this problem.

When I searched for related materials, I found that playing videos directly using MediaPlayer and SurfaceView, instead of using VideoView, can free me from audio focus problems. (VideoView also plays videos internally using MediaPlayer and SurfaceView)

Please refer to the code below to remove VideoView and play the video yourself in the above way.

Stack overflow post posted with the same issue


2022-09-21 17:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.