How to manipulate audio channels volume with AudioTrack.setVolume after API 21

谁都会走 提交于 2019-12-10 15:29:50

问题


I'm trying to reproduce a mono wav file over just one of the stereo channels (speakers) that my smartphone has. I used to control this with

AudioTrack.setStereoVolume (float leftGain, float rightGain)

by setting one of these gains to zero. Reviewing an old code I got a deprecated method warning and after checking Android SDK documentation I've found it is now done by :

public int setVolume (float gain)

Added in API level 21. This API is preferred over setStereoVolume(float, float), as it more gracefully scales down to mono, and up to multi-channel content beyond stereo.

My questions are:

  1. How would I control the channels volume individually so that only one channel reproduces at a given time now that I'm supposed to control both channels at the same time with the new version of the method?
  2. Is there a way to check through Android API if a certain device has stereo or mono speakers?
  3. Is there another way to reproduce mono audio through a single speaker only?

来源:https://stackoverflow.com/questions/36904903/how-to-manipulate-audio-channels-volume-with-audiotrack-setvolume-after-api-21

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