How to modify audio processors on the fly

馋奶兔 提交于 2019-12-13 03:48:46

问题


I need to implement audio channel mapping using ExoPlayer so that I can listen to one channel from both earphones at the time.

For that I am using ChannelMappingAudioProcessor and it works, except I need to be able to change the mapping on the fly.

The thing is, you can define the processors when creating an instance of the ExoPlayer (I do it with Dagger and I inject it into the ViewModel) but once instance is created, there is no way (afaik) to get the processor/renderer from the instance and modify it.

player creation:

    @Provides
    @Singleton
    fun provideMediaPlayer(application: Application): SimpleExoPlayer {
        return ExoPlayerFactory.newSimpleInstance(
            application,
            object : DefaultRenderersFactory(application) {
                override fun buildAudioProcessors(): Array<AudioProcessor> {
                    return arrayOf(ChannelMappingAudioProcessor().apply {
                        //left channel only
                        setChannelMap(intArrayOf(0, 0))
                        configure(DEVICE_AUDIO_SAMPLE_RATE, 2, C.ENCODING_PCM_16BIT)
                    })
                }
            },
            DefaultTrackSelector(),
            DefaultLoadControl.Builder()
                .setBufferDurationsMs(10, 10, 4, 10)
                .createDefaultLoadControl()
        )
    }

player usage:

//stream audio from remote raspberry PI device
player.playStream(url)

//playStream()
fun SimpleExoPlayer.playStream(address: String) {
    val mediaUri = Uri.parse(address)
    val mediaSource = ProgressiveMediaSource.Factory(
        DefaultHttpDataSourceFactory(
            "${BuildConfig.APP_NAME}/${BuildConfig.VERSION_NAME} (Linux;Android ${Build.VERSION.RELEASE}) ${ExoPlayerLibraryInfo.VERSION_SLASHY}"
        )
    ).createMediaSource(mediaUri)
    this.prepare(mediaSource)
    this.playWhenReady = true
}

I want to be able to access the ChannelMappingAudioProcessor and reconfigure it on the fly, so that I can change the channel mapping at runtime. From what this guy wrote, it should be possible somehow.


回答1:


Well it's possible if your processor implementation reads a variable whether it should actually process something or bypass the processor. AFAIK you cant change the processor chain and runtime, but you can bypass any processor by configuration.

Take this pseudo-ish kotlin for reference - i hope you get the idea:

https://gist.github.com/l0rn/1c4808f260161d7a486277bdf50d008d



来源:https://stackoverflow.com/questions/57688372/how-to-modify-audio-processors-on-the-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!