Dealing with Audio Output Hardware 处理音频输出硬件设备
来源:互联网 发布:我看网络直播 即评 编辑:程序博客网 时间:2024/05/23 16:20
Users have a number of alternatives when it comes to enjoying the audio from their Android devices. Most devices have a built-in speaker, headphone jacks for wired headsets, and many also feature Bluetooth connectivity and support for A2DP audio.
Check What Hardware is Being Used
How your app behaves might be affected by which hardware its output is being routed to.
You can query the AudioManager
to determine if the audio is currently being routed to the device speaker, wired headset, or attached Bluetooth device as shown in the following snippet:
if (isBluetoothA2dpOn()) { // Adjust output for Bluetooth.} else if (isSpeakerphoneOn()) { // Adjust output for Speakerphone.} else if (isWiredHeadsetOn()) { // Adjust output for headsets} else { // If audio plays and noone can hear it, is it still playing?}//http://blog.csdn.net/sergeycao
Handle Changes in the Audio Output Hardware
When a headset is unplugged, or a Bluetooth device disconnected, the audio stream automatically reroutes to the built in speaker. If you listen to your music at as high a volume as I do, that can be a noisy surprise.
Luckily the system broadcasts an ACTION_AUDIO_BECOMING_NOISY
intent when this happens. It’s good practice to register aBroadcastReceiver
that listens for this intent whenever you’re playing audio. In the case of music players, users typically expect the playback to be paused—while for games you may choose to significantly lower the volume.
private class NoisyAudioStreamReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { // Pause the playback } }}private IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);private void startPlayback() { registerReceiver(myNoisyAudioStreamReceiver(), intentFilter);}private void stopPlayback() { unregisterReceiver(myNoisyAudioStreamReceiver);}
- Dealing with Audio Output Hardware 处理音频输出硬件设备
- Dealing with Audio Output Hardware
- Managing Audio Playback之Dealing with Audio Output Hardware
- Android---处理音频输出的硬件
- Android Developers:处理音频输出的硬件
- Android---处理音频输出的硬件
- 创建多媒体APP 之 音频播放:处理音频输出硬件
- Audio Queue 音频处理
- Audio音频输出通道切换
- Android audio加载output设备列表流程图
- 理解线程/多线程处理数组(MultiThreaded dealing with arrays)
- 【Android】Audio音频输出通道切换
- 【Android】Audio音频输出通道切换
- [iOS]获取设备Hardware Model(硬件模型)
- Dealing with Adversity
- How can I capture the audio output with GStreamer?
- Hi35xx音频(AUDIO)处理模块
- Hi35xx音频(AUDIO)处理模块
- typedef
- python 文件操作
- 解决phpcas中的单点登出问题
- 接触到的软件
- C#修改config文件实现动态调用webservice实现问题
- Dealing with Audio Output Hardware 处理音频输出硬件设备
- ASP.NET:性能与缓存
- DBMS_STATS.GATHER_TABLE_STATS
- 页面出现滚动条时会出现抖动现象
- 引用计数+写时拷贝
- POJ 1436 Horizontally Visible Segments (线段树)
- Monitoring the Battery Level and Charging State 监测电池电量和充电状态
- 图标设计之道
- MediaElement的视频循环播放