Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not stable audio session, at first start. #6975

Closed
master255 opened this issue Feb 13, 2020 · 12 comments
Closed

Not stable audio session, at first start. #6975

master255 opened this issue Feb 13, 2020 · 12 comments
Assignees
Labels

Comments

@master255
Copy link

master255 commented Feb 13, 2020

The first start of the player gives the audio session ID, but once in 5-15 times it does not work. The ID comes through the onAudioSessionId(int id) event {}. Track in flac format.
ID comes correctly, but music is not transmitted through it.
At the same time mMediaPlayer.getAudioSessionId() returns the same, not working ID.
The player plays music correctly but does not pass it to audiosessionId.

Device: Samsung Galaxy s8+ Android 8.0
Version ExoPlayer 2.11.2
I checked the same scenario on other player modules. Classic player and VLC player do not have such a bug.

@kim-vde
Copy link
Contributor

kim-vde commented Feb 14, 2020

Please provide complete information as requested in the issue template. The issue template can be found here. If you're unable to share bug reports or test content publicly, please send them to dev.exoplayer@gmail.com using a subject in the format "Issue #1234", where "#1234" should be replaced with your issue number. Please also update this issue to indicate you’ve done this.

@kim-vde kim-vde self-assigned this Feb 14, 2020
@master255
Copy link
Author

master255 commented Feb 14, 2020

@kim-vde
[REQUIRED] Issue description
The first start of the player gives the audio session ID, but once in 5-15 times it does not work. The ID comes through the onAudioSessionId(int id) event {}. Track in flac format.
ID comes correctly, but music is not transmitted through it.
At the same time mMediaPlayer.getAudioSessionId() returns the same, not working ID.
The player plays music correctly but does not pass it to audiosessionId.
Expected: audio session always works stable.

[REQUIRED] Reproduction steps
To reproduce the problem, start the player 5-20 times and make sure that the audio session works correctly. To do this you need to use it with EQ or Visualizer.

[REQUIRED] Link to test content
You must create an example yourself. The problem is reproduced with any Flac file.

[REQUIRED] A full bug report captured from the device
Bug report in the attachment. It's taken right after the bug appeared.

[REQUIRED] Version of ExoPlayer being used
2.11.2

[REQUIRED] Device(s) and version(s) of Android being used
Samsung Galaxy S8+, Android 8.0.
bugreport-2020-02-14-14-52-26.zip

@kim-vde
Copy link
Contributor

kim-vde commented Feb 14, 2020

Could you please send a minimal piece of code that I could use to reproduce? Also, what is the type of mMediaPlayer?

@kim-vde
Copy link
Contributor

kim-vde commented Feb 14, 2020

I tried to reproduce the issue but I couldn't. Here is the sample code that I used:

 player.addAudioListener(
          new AudioListener() {
            @Override
            @TargetApi(29)
            public void onAudioSessionId(int audioSessionId) {
              if (equalizer != null) {
                equalizer.release();
              }
              equalizer = new Equalizer(/* priority= */ 0, audioSessionId);
              short minimumBandLevel = equalizer.getBandLevelRange()[0];
              for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
                equalizer.setBandLevel(i, minimumBandLevel);
              }
              equalizer.setEnabled(true);
            }
          });

@master255
Copy link
Author

master255 commented Feb 14, 2020

@kim-vde , I just checked. This problem only happens with Visualizer.
And if you turn on the equalizer with Visualizer, the problem goes away.
Bug only happens when the EQ is off and Visualizer is on.

I use SimpleExoPlayer. I tried to change all the settings and the bug is reproduced anyway.

@master255
Copy link
Author

master255 commented Feb 14, 2020

@kim-vde I just tried to add Visualizer to the Demo application and got the following errors:

020-02-14 22:03:52.028 6994-6994/com.google.android.exoplayer2.demo E/AudioEffect: set(): AudioFlinger could not create effect, status: -1
2020-02-14 22:03:52.028 6994-6994/com.google.android.exoplayer2.demo E/visualizers-JNI: Visualizer initCheck failed -3
2020-02-14 22:03:52.028 6994-6994/com.google.android.exoplayer2.demo E/Visualizer-JAVA: Error code -3 when initializing Visualizer.
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at android.media.audiofx.Visualizer.<init>(Unknown Source:112)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at visualizer.VisualizerView.link(VisualizerView.java:85)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at com.google.android.exoplayer2.demo.PlayerActivity$1.onAudioSessionId(PlayerActivity.java:392)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at com.google.android.exoplayer2.SimpleExoPlayer$ComponentListener.onAudioSessionId(SimpleExoPlayer.java:1643)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at com.google.android.exoplayer2.audio.AudioRendererEventListener$EventDispatcher.lambda$audioSessionId$5$AudioRendererEventListener$EventDispatcher(AudioRendererEventListener.java:170)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at com.google.android.exoplayer2.audio.-$$Lambda$AudioRendererEventListener$EventDispatcher$a1B1YBHhPRCtc1MQAc2fSVEo22I.run(Unknown Source:4)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at android.os.Handler.handleCallback(Unknown Source:2)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at android.os.Handler.dispatchMessage(Unknown Source:4)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at android.os.Looper.loop(Unknown Source:139)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at android.app.ActivityThread.main(Unknown Source:146)
2020-02-14 22:03:52.029 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2020-02-14 22:03:52.030 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Unknown Source:11)
2020-02-14 22:03:52.030 6994-6994/com.google.android.exoplayer2.demo W/System.err:     at com.android.internal.os.ZygoteInit.main(Unknown Source:198)

@master255
Copy link
Author

@kim-vde This error is due to the fact that I did not add the permission to record the sound. Now I'm testing...

@master255
Copy link
Author

master255 commented Feb 14, 2020

@kim-vde It's hard to reproduce. I found the truth! An audio session doesn't work if it's generated when the application has no audio focus. Only in Visualizer.

@master255
Copy link
Author

@kim-vde No. I get an audio focus, but the session still doesn't work. Testing. Don't close the bug.

@master255
Copy link
Author

@kim-vde Perfect! I found the bug! And I was able to finish the demo application so it could reproduce it, too.
The app's in the attachment.
Bug calls the line: player.seekTo(2147);
When I need to restore the audio position, it happens. And one time out of 5-20 player launches.
http://master255.org/res/%d0%9c%d1%83%d0%b7%d1%8b%d0%ba%d0%b0/0-9/3rd%20Force/3rd%20Force%20-%20Here%20Comes%20The%20Night.flac
Place the file like this:
"name": "Misc",
"samples." [
{
"name": "Dizzy (MP4)."
"uri": "/storage/emulated/0/MediaLibrary/3rd Force - Here Comes The Night. flac"
},
Then it must be restarted several times and you will get a non-working audio session. Tadaa!

main.zip

@master255
Copy link
Author

And I've already won the bug with that logic:
boolean haveStartPosition = startWindow != C.INDEX_UNSET;
if (haveStartPosition) {
player.seekTo(startWindow, startPosition);
}
player.prepare(mediaSource, !haveStartPosition, false);

If you don't think it's a bug, you can close it.
But there's a problem with the audio session. It just doesn't interfere with the processes right now.

@kim-vde
Copy link
Contributor

kim-vde commented Feb 18, 2020

What happens is that the visualiser is configured while the audio track is being released and rebuilt. Sometimes, the audio track does not exist anymore when the visualiser accesses it, which causes the bug.

To fix this, you have 2 possibilities:

  • You can pass a generated audio session id by using something like audioSink.setAudioSessionId(C.generateAudioSessionIdV21(context)). To do that, you would need to subclass DefaultRenderersFactory and update the audio sink provided to the MediaCodecAudioRenderer in method buildAudioRenderers(). Note that this would only work from API level 21 so it wouldn't fix the issue if you are targetting lower API levels.
  • You can retry to create the visualiser every time visualiser.setDataCaptureListener(), visualiser.setCaptureSize() or visualiser.setEnabled() returns a status different from SUCCESS.

We already have plans to avoid recreating audio tracks when possible. Hopefully, this will fix this bug.

ojw28 pushed a commit that referenced this issue Mar 10, 2020
Issue: #6975
PiperOrigin-RevId: 299328798
@kim-vde kim-vde closed this as completed Mar 25, 2020
@google google locked and limited conversation to collaborators May 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants