Spaces:
Running
Running
Download static/js/audio-table.js from TrustSafeAI/AudioPerturber: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/spaces/TrustSafeAI/AudioPerturber/resolve/main/static/js/audio-table.js
- Command line
-
hf download hf://spaces/TrustSafeAI/AudioPerturber/static/js/audio-table.js
-
curl -L -o audio-table.js https://huggingface.co/spaces/TrustSafeAI/AudioPerturber/resolve/main/static/js/audio-table.js
1.57 kB
| // Audio Table Control Scripts | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const audioElements = document.querySelectorAll('.audio-player, audio[controls]'); | |
| // 当播放一个音频时,暂停其他所有音频 | |
| function pauseOtherAudios(currentAudio) { | |
| audioElements.forEach(audio => { | |
| if (audio !== currentAudio && !audio.paused) { | |
| audio.pause(); | |
| } | |
| }); | |
| } | |
| // 为每个音频元素添加播放事件监听器 | |
| audioElements.forEach(audio => { | |
| audio.addEventListener('play', function() { | |
| pauseOtherAudios(this); | |
| }); | |
| // 加载开始 | |
| audio.addEventListener('loadstart', function() { | |
| this.classList.add('loading'); | |
| }); | |
| // 加载完成 | |
| audio.addEventListener('canplay', function() { | |
| this.classList.remove('loading'); | |
| }); | |
| // 错误处理 | |
| audio.addEventListener('error', function() { | |
| console.log('Audio loading failed:', this.src); | |
| this.classList.remove('loading'); | |
| }); | |
| }); | |
| // 添加键盘控制(可选功能) | |
| document.addEventListener('keydown', function(e) { | |
| // 按空格键暂停所有音频 | |
| if (e.code === 'Space' && e.target.tagName !== 'INPUT') { | |
| e.preventDefault(); | |
| audioElements.forEach(audio => { | |
| if (!audio.paused) { | |
| audio.pause(); | |
| } | |
| }); | |
| } | |
| }); | |
| }); |