Has anyone tried to play sounds through the speakers and headphones at the same time? Android + iOS

柔情痞子 提交于 2019-12-25 02:28:18

问题


I currently have an app that generates sounds on the fly, like pure tones and white noise, and I can hear that on the headphones. Is it possible to send the same signal to the internal speakers and the headphones at the same time? I would like to do this on iOS 7 and KitKat. Probably, Android L and iOS 8 in the future...

On iOS I have seen that a new feature was introduced on iOS 6, multiroute, which let select the audio route. The thing is that when I connect the headphones I can not choose the internal speakers. Maybe I am doing something wrong. I think that would help me on Android...

On Android, I have found this simultaneously using a headphone and speaker. But that is from one year ago.

Has anyone tried this?

Thanks!


回答1:


On iOS, I don't think you can route audio to both the headphones and the speakers. You can control the routing to different audio interfaces using the multi-route audio code included in this Apple WWDC slideshow, but the built-in headphone jack and speakers are part of the same audio interface, and I don't think there is a way to override the behavior within that interface of disabling the speaker when the headphones are connected.




回答2:


To do this on Android, it should suffice to set your audio stream to STREAM_ALARM:

MediaPlayer player = new MediaPlayer();
//
// Your player initialisation code here
//
player.setAudioStreamType(AudioManager.STREAM_ALARM);


来源:https://stackoverflow.com/questions/25451692/has-anyone-tried-to-play-sounds-through-the-speakers-and-headphones-at-the-same

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