播放声音在音箱同时通过耳机播放音乐音箱、耳机、声音、音乐

2023-09-13 00:55:35 作者:り 醉染

我有一个 AudioTrack 流通过耳机。我要送一个的Soundpool 内置的扬声器只,而不会中断 AudioTrack 打了耳机。任何黑客歹徒?

I have an AudioTrack streaming via headphones. I have to send a SoundPool to built-in speakers only, without interrupting the AudioTrack playing over the headphones. Any hacks gangsters?

推荐答案

许多Android设备使用一个单一的输出线在AudioFlinger /音频HAL为所有本地播放(听筒,扬声器,有线耳机/耳机),使不同的路由两个轨道同时是不可能的(这就是为什么在许多设备上,如果一个通告播放,你已经有了一个连接有线耳机的媒体流被强制静音,否则你会听到音乐的扬声器,而通告播放)。

Many Android devices use a single output thread in the AudioFlinger / audio HAL for all local playback (earpiece, speaker, wired headset/headphones), making different routing of two tracks simultaneously impossible (which is why on many devices the media streams are forcibly muted if a notification is played and you've got a wired headset attached; because otherwise you'd hear the music in the loudspeaker while the notification is played).

在某些设备有可能这样做,你要寻找的,如果你成功地做了 setForceUse(FOR_MEDIA,FORCE_SPEAKER)并使用音乐流类型要在扬声器播放的东西,为的东西,你要玩的 VOICE_CALL 流类型有线耳机。 我不知道是否有任何方式的应用程序,虽然执行 setForceUse 通话。也许你可以在通过反射的 AudioService 类的的handleMessage 方法并发送一个 MSG_SET_FORCE_USE 的短信..我从来没有尝试过自己,因此可能会惨遭失败。

On some devices it might be possible to do what you're looking for if you manage to do a setForceUse(FOR_MEDIA, FORCE_SPEAKER) and use the MUSIC stream type for the stuff you want to play in the loudspeaker, and the VOICE_CALL stream type for the stuff that you want to play in the wired headset. I'm not sure if there's any way for an application to perform that setForceUse call though. Perhaps you can get at the handleMessage method of the AudioService class through reflection and send it an MSG_SET_FORCE_USE message.. I've never tried it myself so it might fail miserably.

编辑:我现在已经测试过迫使媒体流,同时将有线耳机连接在实际设备上扬声器的setForceUse方式,而它的工作(虽然我不能保证它会在所有设备工作)。实施是从我上面描述略有差异。见我的回答how打开扬声器/关闭编程中的Andr​​oid 4.0 为code我用。

I've now tested the setForceUse way of forcing MEDIA streams to the loudspeaker while a wired headset is attached on an actual device, and it does work (though I can't guarantee that it will work across all devices). The implementation was slightly different from what I described above. See my answer to how to turn speaker on/off programatically in android 4.0 for the code I used.

 
精彩推荐