简体   繁体   English

具有输入范围的 HTML 音频可访问性

[英]HTML Audio accessibility with Input Range

Minimal problem example: https://codepen.io/sidouglas/pen/LYPZaOG最小问题示例: https : //codepen.io/sidouglas/pen/LYPZaOG

When input range is focused , with either Chrome Vox or Mac's Voice over — every value of valuetext is read out continuously.当输入范围被聚焦时,无论是 Chrome Vox 还是 Mac 的 Voice over - valuetext每个值valuetext被连续读出。

<input
 ...
  v-bind:aria-valuemax="valueMax"
  v-bind:aria-valuenow="valueNow"
  v-bind:aria-valuetext="currentTime + ' of ' + totalDuration"
  ...
/>

Contrast this to the very accessible https://plyr.io/#audio component - When focused it continues to update its aria values, yet only announce to the screen reader twice.将此与非常易于访问的https://plyr.io/#audio组件进行对比 - 当聚焦时,它会继续更新其 aria 值,但只向屏幕阅读器宣布两次。

Does anyone know how plyr does it?有谁知道plyr是怎么做的?

 new Vue({ el: '#range', data: { valueMax:100, duration:100, current:0, totalDuration:'1:40' }, computed:{ currentTime: function() { return this.convertTime(this.current); }, valueNow() { return Math.round(this.current); }, }, methods: { convertTime(time) { const minutes = Math.floor(time / 60); const seconds = time - (minutes * 60); return `${minutes}:${seconds.toFixed(0).toString().padStart(2, '0')}`; }, }, mounted: function(){ var self = this; setInterval(function(){ self.current = Number(self.current) + 1; if(self.current >= self.valueMax){ self.current = 0; } },2000); }, });
 .audio-file-player__slider-range{ border:1px solid red; width:100%; } .audio-file-player__slider-range:focus { box-shadow: 0 0 10px blue; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="range"> <input aria-label="Seek" aria-valuemin="0" autocomplete="off" class="audio-file-player__slider-range u-color-gray-111111 u-width-100" min="0" role="slider" step="1" type="range" v-bind:aria-valuemax="valueMax" v-bind:aria-valuenow="valueNow" v-bind:aria-valuetext="currentTime + ' of ' + totalDuration" v-bind:max="duration" v-model="current" /> <p>current: {{ current }}</p> <p>aria-valuenow: {{ valueNow }}</p> <p>aria-valuetext: {{ currentTime + ' of ' + totalDuration }}</p> </div>

For anyone who comes across this the easy solution is to override the value using aria-valuetext .对于遇到此问题的任何人,简单的解决方案是使用aria-valuetext覆盖该值。

When the item is playing I would set the aria-valuetext to 'current: currentTime , remaining: remainingTime ' when it first receives focus .当项目正在播放我的设置aria-valuetext到目前的: currentTime :,其余remainingTime当它第一次获得焦点“。

Then do not update the time while the item is playing (leave the aria-valuetext alone).然后不要在项目播放时更新时间(单独留下aria-valuetext )。

Then when play is paused / stopped change the aria-valuetext again to reflect the current time.然后当播放暂停/停止时再次更改aria-valuetext以反映当前时间。

Finally I would update the current time on a throttle of say 200ms for when someone is seeking using the arrow keys.最后,当有人使用箭头键进行搜索时,我会以 200 毫秒的节流速度更新当前时间。

You can decide whether to do this while playing or only when not playing as I am not sure which is the best solution in terms of information vs interruption.您可以决定是在玩游戏时执行此操作,还是仅在不玩游戏时执行此操作,因为我不确定在信息与中断方面哪个是最佳解决方案。

I would lean towards not updating while playing as a user could always tab to the current time if you made that focusable.我倾向于在玩游戏时不更新,因为如果您将其设为可聚焦,则用户始终可以选择当前时间。

By doing this you can ensure that it does not interfere with playing music or announce 200 different times.通过这样做,您可以确保它不会干扰播放音乐或宣布 200 次不同的时间。

plyr.io theory - it repeated for me too at first, then I changed my settings on announce speed. plyr.io 理论-起初它也为我重复,然后我更改了宣布速度的设置。 I believe the reason some people do and some people don't get announcements is the speed at which they update the current time (looks like 3-4 times a second) and I think that repeats so quickly that the Screen Reader decides not to confuse the user with it.我相信有些人这样做而有些人没有收到公告的原因是他们更新当前时间的速度(看起来像每秒 3-4 次)而且我认为这种重复如此之快以至于屏幕阅读器决定不混淆用它的用户。 Only a theory but my best guess as they aren't doing anything clever I can see.只是一个理论,但我最好的猜测,因为他们没有做任何我能看到的聪明的事情。

Turn your song path into a computed property then get its currentTime.将您的歌曲路径转换为计算属性,然后获取其 currentTime。 Like below:像下面这样:

<template>
  <div>
    <h3>Audio Player Test</h3>

    <audio
      ref="myMusic"
      src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"
      @timeupdate="onTimeUpdateListener"
    ></audio>
    {{currentTime}}
    <button @click="play">Play</button>
    <button @click="pause">Pause</button>
  </div>
</template>
data() {
    return {
      songCurrent: 0,
      currentTime: "00:00" // The initial current time
    };
},
computed: {
    song() {
      return this.$refs.myMusic;
    }
}
methods: {
    play() {
      this.song.play();
    },
    pause() {
      this.song.pause();
    },
    onTimeUpdateListener: function() {
      // Update current time
      this.currentTime = this.$refs.myMusic.currentTime;
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM