Android force HDMI audio

六月ゝ 毕业季﹏ 提交于 2019-12-12 12:13:43

问题


My ADT-1 does not play sound over HDMI when connected to the TV.

On that specific TV I had to force HDMI audio on the Raspberry PI, so I'm trying to force it on the ADT-1 as well.

I tried making an app with the permission

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

And using an AudioManager instance to change the settings

AudioManager manager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);    
Log.d(TAG, "ATTACHED: " + manager.getParameters("attached_output_devices"));
Log.d(TAG, "DEFAULT: " + manager.getParameters("default_output_device"));
Log.d(TAG, "PRE: " + manager.getParameters("audio_devices_out_active"));       
manager.setParameters("audio_devices_out_active=AUDIO_DEVICE_OUT_AUX_DIGITAL");
Log.d(TAG, "POST: " + manager.getParameters("audio_devices_out_active"));

but all the logs are returning empty, and there's no change in the audio.

ATTACHED: attached_output_devices=
DEFAULT: default_output_device=
PRE: audio_devices_out_active=
POST: audio_devices_out_active=

I read about TV Audio from the TIF (TV Input Framework) and the possibility to set audio patches, but I don't think that's the case, this seems more due to the TV being seen only as an HDMI monitor with no audio capabilities.

the file /etc/audio_policy.conf shows:

global_configuration{
 attached_output_devices AUDIO_DEVICE_OUT_SPEAKER
 default_output_device AUDIO_DEVICE_OUT_SPEAKER
 ...
}

audio_hw_modules {
 outputs{
  primary{
   ...
   devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_AUX_DIGITAL
   flags AUDIO_OUTPUT_FLAG_PRIMARY
  }
 }
}

Where AUDIO_DEVICE_OUT_AUX_DIGITAL is the HDMI.

Any idea on how to force ADT-1 to output audio on HDMI?


回答1:


Use

    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

in your manifest and

    audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setParameters("audio_devices_out_active=AUDIO_CODEC");
    // or 
    audioManager.setParameters("audio_devices_out_active=AUDIO_HDMI");
    // or 
    audioManager.setParameters("audio_devices_out_active=AUDIO_HDMI,AUDIO_CODEC");

in your code for setting the active audio output



来源:https://stackoverflow.com/questions/31909040/android-force-hdmi-audio

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