Android SeekBar对讲,说得太多了

问题描述 投票:1回答:2

(Android)在音乐播放器上,您可以按预期更新搜索栏:

PRECISION_SEEKBAR = 100000;
((SeekBar) findViewById(R.id.seekBar2)).setMax(PRECISION_SEEKBAR);

timerSeekBarUpdate.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                final SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);

                @Override
                public void run() {
                    if (control == null || player == null) {
                        cancel();
                        return;
                    }
                    seekBar.setProgress((int) (player.getCurrentPosition() * PRECISION_SEEKBAR / player.getDuration()));
                    ...

但是,如果焦点在搜索栏上,则会稳定地进行对讲,并且不间断地为进度提供反馈。如“寻求控制25%”,“寻求控制25%”,“寻求控制25%”,“寻求控制26%”,“寻求控制26%”,“寻求控制27%”

我错过了,但无法解决问题。我已将contentDescription设置为@null以外的其他内容。但是这次它不停地读取内容描述。

在Spotify客户端上,我检查过,它将进度读作“xx percent”一次。尽管将重点放在了搜索栏上。

当我将精度编辑为1或100时,会丢失搜索条上的精度。看起来歌曲中有一些部分。您可以通过在搜索栏上滑动来播放一个或另一个。

有没有人经历过这样的事?我在谷歌文档,堆栈网络或其他地方找不到任何东西。

java android accessibility talkback
2个回答
0
投票

我遇到了问题,发现SeekBar会在每次更新时读取百分比。

它有帮助,我只在百分比改变但仍然保持高精度(在我的情况下以毫秒为单位)时更新SeekBar。

@Override
public void updateSeekBar(final int currentPosInMillis, final int durationInMillis) {
    long progressPercent = calculatePercent(currentPosInMillis, durationInMillis);

    if (progressPercent != previousProgressPercent) {
        seekBar.setMax(durationInMillis);
        seekBar.setProgress(currentPosInMillis);
    }
    previousProgressPercent = progressPercent;
}

private int calculatePercent(int currentPosInMillis, int durationInMillis) {
    if(durationInMillis == 0) {
        return 0;
    }
    return (int) (((float)currentPosInMillis / durationInMillis) * 100);
} 

previousProgressPercent初始化为-1。

请注意,此解决方案与Spotify不同。 当SeekBar被选中时,Spotify会覆盖系统公布的消息。 这有以下两种效果:

  • 可以根据需要随时进行更新,而不会重复百分比
  • 当选择SeekBar时百分比发生变化,则不会宣布任何内容

第2点可能是一个缺点,取决于你想要达到的目标。


0
投票

您可以覆盖sendAccessibilityEvent(),以便忽略描述更新:

@Override
public void sendAccessibilityEvent(int eventType) {
    if (eventType != AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION) {
        super.sendAccessibilityEvent(eventType);
    }
}

正如Altoyyr所提到的,这会产生忽略所有描述更新的副作用,包括滚动音量按钮。因此,您需要添加回发送卷事件操作的事件:

@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    switch (action) {
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
            super.sendAccessibilityEvent(AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION);
        }
    }
    return super.performAccessibilityAction(action, arguments);
}
© www.soinside.com 2019 - 2024. All rights reserved.