Сan't initialize Audio Effect with error code -3
@marcbaechinger is already working on this.
Since Apr 11, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Perhaps, similar problems:
https://stackoverflow.com/questions/73911184/cannot-conect-audiotrack-to-audiofx-equalizer-in-kotlin
https://github.com/GautamChibde/android-audio-visualizer/issues/9
Traceback:
2024-04-10 18:03:23.278 11549-11549 Token me.example.mediaplayer I 10788 // session ID
2024-04-10 18:03:23.283 11549-11549 AudioEffect me.example.mediaplayer E set(): AudioFlinger could not create effect 0bed4300-ddd6-11db-8f34-0002a5d5c51b / ec7178ec-e5e1-4432-a3f4-4657e6795210, status: -22
2024-04-10 18:03:23.283 11549-11549 AudioEffects-JNI me.example.mediaplayer E AudioEffect initCheck failed -3
2024-04-10 18:03:23.283 11549-11549 AudioEffect-JAVA me.example.mediaplayer E Error code -3 when initializing AudioEffect.
2024-04-10 18:03:23.294 11549-11549 AbstractFuture me.example.mediaplayer E RuntimeException while executing runnable me.example.mediaplayer.MainActivity$$ExternalSyntheticLambda4@dce6a30 with executor MoreExecutors.directExecutor()
java.lang.RuntimeException: Cannot initialize effect engine for type: 0bed4300-ddd6-11db-8f34-0002a5d5c51b Error: -3
at android.media.audiofx.AudioEffect.<init>(AudioEffect.java:545)
at android.media.audiofx.AudioEffect.<init>(AudioEffect.java:503)
at android.media.audiofx.AudioEffect.<init>(AudioEffect.java:477)
at android.media.audiofx.Equalizer.<init>(Equalizer.java:139)
at me.example.mediaplayer.effects.XEqualizer.<init>(AudioEffectUtils.kt:46)
at me.example.mediaplayer.effects.AudioEffectManager.<init>(AudioEffectUtils.kt:13)
at me.example.mediaplayer.views.PlayerPage.initializeAudioControllers$app_debug(MainPages.kt:354)
at me.example.mediaplayer.views.PlayerPage.initializeAudioControllers$app_debug$default(MainPages.kt:340)
AudioEffectManage and Equalizer are wrappers over classes from your library.
That's how I get the token:
private val mediaSessionToken: SessionToken by lazy {
SessionToken(
this,
ComponentName(this, MediaService::class.java)
)
}
private val mediaControllerFuture by lazy {
MediaController
.Builder(this, mediaSessionToken)
.buildAsync()
}
private var mediaController: MediaController? = null
private val audioManager: AudioManager by lazy {
this@MainActivity.getSystemService(Context.AUDIO_SERVICE) as AudioManager
}
My background service:
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
class MediaService : MediaSessionService() {
private var mediaSession: MediaSession? = null
override fun onCreate() {
super.onCreate()
mediaSession = MediaSession
.Builder(
this,
ExoPlayer
.Builder(this)
.build()
)
.build()
}
override fun onDestroy() {
mediaSession?.run {
player.release()
release()
mediaSession = null
}
super.onDestroy()
}
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) : MediaSession? =
mediaSession
}
Listening to the creation of the controller:
mediaControllerFuture
.addListener({
pagesAdapter.initializeAudioControllers(
mediaSessionToken.uid,
mediaControllerFuture.get(),
mediaSessionToken
)
}, MoreExecutors.directExecutor())
And connect effects:
fun initializeAudioControllers(
audioSessionID: Int,
audioController: MediaController,
sessionToken: SessionToken,
) {
this.audioController = audioController
this.sessionToken = sessionToken
Log.i("Token", audioSessionID.toString()) // 10788
this@PlayerPage.effectsManager?.equalizer?.enabled = false // does not affect
this@PlayerPage.effectsManager?.bassBoost?.enabled = false // does not affect
this@PlayerPage.effectsManager = AudioEffectManager(audioSessionID) // exception
}
The strangest thing is that this error occurred about two days ago, I fixed it by removing <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> from the manifest (but the effects were still not applied, or I do not know how to distinguish them). Now I was experimenting with the interface, and the error occurred again. I rolled back to the commit that I made as soon as the error disappeared (!), but it remained!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.