我有一个应用程序,可以播放基于谷歌文档的播放列表如何创建和音频应用程序https://developer.android.com/guide/topics/media-apps/audio-app/building-an-audio-app
我想添加一个均衡器,就像这个https://github.com/Yalantis/Horizon,但我找不到如何获得所需的信息,我以前从未处理过声音,所以我有点迷路。
根据文档,我应该首先:“初始化Horizon对象,参数引用你的声音:”
mHorizon = Horizon(
glSurfaceView, ResourcesCompat.getColor(resources, R.color.grey2),
RECORDER_SAMPLE_RATE, RECORDER_CHANNELS, RECORDER_ENCODING_BIT //Where to get these 3 constants?
)然后:“要使用声音数据块更新Horizon调用updateView方法,请继续:”
val buffer = ByteArray(//Where to get the bytes?)
mHorizon!!.updateView(buffer)我怎样才能得到这些数据呢?我查看了android文档,但什么也找不到。
发布于 2020-05-20 23:18:52
你需要在你的Exoplayer中添加一个自定义的RendererFactory来获取音频字节。请参见以下代码:
val rendererFactory = RendererFactory(this, object : TeeAudioProcessor.AudioBufferSink {
override fun flush(sampleRateHz: Int, channelCount: Int, encoding: Int) {
}
override fun handleBuffer(buffer: ByteBuffer) {
//pass bytes to the your function
}
})
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, rendererFactory,DefaultTrackSelector())您将获得ByteBuffer中的字节,以便使用以下代码将其转换为ByteArray:
try{
val arr = ByteArray(buffer.remaining())
buffer[arr] //pass this array to the required function
}
catch(exception:Exception)
{
// handle exception here
}https://stackoverflow.com/questions/61600937
复制相似问题