1.獲取音頻輸出列表
有個需求是APP端能夠獲取所有音頻輸出列表,研究了很長時間源碼,發(fā)現(xiàn)只有這個API合適。
AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
這個API能夠獲取到設(shè)備上所有可用的輸出,且APP可以調(diào)用。文章來源:http://www.zghlxwxcb.cn/news/detail-586105.html
2.設(shè)置音頻輸出通道
需要在framework層修改,找一個Manager或者自己寫一個Manager,添加以下API方法。文章來源地址http://www.zghlxwxcb.cn/news/detail-586105.html
@Override
public void setPreferredDevice(int type) {
AudioDeviceInfo device = null;
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
for(AudioDeviceInfo dev : devices) {
if(dev.getType() == type && type != 0){
device = dev;
break;
}
}
if (device == null) {
Log.i(TAG, "Skip se
到了這里,關(guān)于Android12 獲取音頻輸出列表&設(shè)置音頻輸出通道的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!