如何在不散发所有系统的情况下禁用Android TV应用程序中的声音效果
我想在浏览回收视图项目并在Android TV应用中点击声音时禁用声音效果。但是,我不想禁用所有其他声音(例如,应用程序中有超层次的输出声音不应被静音)。
我注意到在stackoverflow上还有其他一些与此相似的问题,建议的解决方案是:
通过设置
android:soundeffectsenabled =“ false”
(我将其放在每个中,请在布局文件中禁用声音效果布局)。但是,这没有任何效果,并且仍然有点击和项目浏览声音效果。使用
audiomanager
禁用声音效果。我尝试了以下内容:audioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_MUTE, 0);
andaudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
These mute all app sounds包括媒体声音。
如果有人可以帮助解决这个问题,我会很感激。谢谢
I would like to disable sound effects when browsing over RecycleView items and also clicking sounds in an Android TV app. But, I do not want to disable all other sounds (e.g., There is Exoplayer in the app that its output sounds should not be muted).
I noticed there are some other questions similar to this on Stackoverflow and the suggested solutions are:
Disable Sound effect in the Layout Files by setting
android:soundEffectsEnabled="false"
(I put this in every Layout). However, this does not have any effect and there is still clicking and item browsing sound effects.Disable sound effects using
AudioManager
. I tried the following:audioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_MUTE, 0);
andaudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
These mute all app sounds including Media sounds.
I would be grateful if someone can help with this issue. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后,我找到了解决这个问题的解决方案。
问题1:在按DPAD_CENTER键上禁用声音效果。我可以通过在CardPresenter(对于Leanback ListrowPresenter)和CardAdapter(用于RecyClerview)中的编程性声音效果来解决此问题。
问题2:对按DPAD导航键禁用声音效果(dpad_right,dpad_left,...)。挖掘
view rootimpl.java
类,事实证明,始终播放导航声音,而无需检查soundeffect
flag。这是view> view rootimpl.java
中的代码的一部分,所以我想到的解决方法是覆盖我的视图中的
requestfocus
方法,并且始终返回false 防止播放效果。
leanback listrowPresenter的代码:
cardPresenter.java
customimagecardview.java
recyclerview的代码:
cardAdapter.java
code> customlinearearearearearlayOut.java
(/code>(/code>(/code>(/code>(/code>(/code>(/code>(/code),)回收器视图的根视图)Finally I found a solution for this problem.
Issue 1: Disabling sound effect on pressing DPAD_CENTER key. I could resolve this issue by programmatically disabling sound effect in CardPresenter (for Leanback ListRowPresenter) and CardAdapter (for RecyclerView).
Issue 2: Disabling sound effect on pressing DPAD navigation keys (DPAD_RIGHT, DPAD_LEFT, ...). Digging into the
ViewRootImpl.java
class, it turns out that navigation sound is always played without checking thesoundEffect
flag. Here is parts of the code inViewRootImpl.java
So a workaround that I came up with is to override the
requestFocus
method in my views and always returnfalse
to prevent playing sound effect.Code for Leanback ListRowPresenter:
CardPresenter.java
CustomImageCardView.java
Code for RecyclerView:
CardAdapter.java
CustomLinearLayout.java
(Root View for Recycler View)如果您只想静音Android电视导航系统声音效果,并且没有自定义导航行为,那么我通过覆盖Onkeydown找到了一种方法。
首先,我在活动和对话框上添加了一个GlobalFocusChangelistener,以聆听并保持重点视图的参考。
其次,我在活动和对话框上覆盖了onkeydown方法,并以这样的方式实施。
这是在Android电视模拟器和我的小米电视上的工作。我认为这种更改不会影响手机或平板电脑的任何触摸行为。
If you just want to mute android tv navigation system sound effect and there is no custom navigation behavior, I found a way by overriding onKeyDown.
First, I added a GlobalFocusChangeListener at Activity and Dialog to listen and keep the reference of focused view.
Second, I overrided onKeyDown method at Activity and Dialog and implement like this.
This is work on android tv emulator and my Xiaomi TV. I think this change will not effect any touch behavior on phone or tablet.