File size: 1,567 Bytes
2c205e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 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();
                }
            });
        }
    });
});