Ypbpr和HDMI是两种视频输出接口,笔者想做一个Service实现两者之间的切换
首先得加上AudioManager与DisplayManager:
Context mContext;
AudioManager mAudioManager = null;
DisplayManager mDisplayManager = null;
public SpdifManager(Context context){
mContext = context;
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mDisplayManager = (DisplayManager) context.getSystemService("display");
}
其次两者之间的切换:
public void SetHdmiMode()
{
mDisplayManager.setDisplayOutputType(0,
DisplayManager.DISPLAY_OUTPUT_TYPE_HDMI, DisplayManager.DISPLAY_TVFORMAT_720P_60HZ);
mDisplayManager.setDisplayMode(DisplayManager.DISPLAY_MODE_SINGLE);//HDMI显示模式
mAudioManager.switchAudioOutMode(AudioManager.AUDIO_OUT_CHANNEL_HDMI);//HDMI声音模式
Settings.System.putString(mContext.getContentResolver(),
"audio_output_channel",AudioManager.auidoOutputChannelCode2Name(AudioManager.AUDIO_OUT_CHANNEL_HDMI));
Settings.System.putString(mContext.getContentResolver(),
"display_output_format", DispList.DISP_FORMAT_NAME_HDMI_720P_60HZ);
}
public void SetYfpbprMode()
{
mDisplayManager.setDisplayOutputType(0,
DisplayManager.DISPLAY_OUTPUT_TYPE_TV, DisplayManager.DISPLAY_TVFORMAT_720P_60HZ);
mDisplayManager.setDisplayMode(DisplayManager.DISPLAY_MODE_SINGLE_VAR);//YPBPR显示模式
mAudioManager.switchAudioOutMode(AudioManager.AUDIO_OUT_CHANNEL_CODEC);//YPBPR声音模式
Settings.System.putString(mContext.getContentResolver(),
"audio_output_channel",AudioManager.auidoOutputChannelCode2Name(AudioManager.AUDIO_OUT_CHANNEL_CODEC));
Settings.System.putString(mContext.getContentResolver(),
"display_output_format", DispList.DISP_FORMAT_NAME_YPBPR_720P_60HZ);
}
最后需要加入system权限和相应的许可:
android:sharedUserId="android.uid.system"