第21行: |
第21行: |
| var audios = document.getElementsByClassName('audio-player'); | | var audios = document.getElementsByClassName('audio-player'); |
| var notValidAudio = /wpDestFile/; | | var notValidAudio = /wpDestFile/; |
− | for(var i=0;i<audios.length;i++) { | + | var currentPlaying = null; |
| + | |
| + | for(var i = 0; i < audios.length; i++) { |
| var audio = audios[i]; | | var audio = audios[i]; |
| var linkEl = audio.firstElementChild; | | var linkEl = audio.firstElementChild; |
第42行: |
第44行: |
| a.src = link; | | a.src = link; |
| a.preload = 'none'; | | a.preload = 'none'; |
| + | |
| + | a.onplay = function () { |
| + | currentPlaying = a; |
| + | this.classList.add('audio-player-playing'); |
| + | this.classList.remove('audio-player-paused'); |
| + | }; |
| + | a.onpause = function () { |
| + | this.classList.add('audio-player-paused'); |
| + | this.classList.remove('audio-player-playing'); |
| + | }; |
| a.onended = function () { | | a.onended = function () { |
| + | currentPlaying = null; |
| this.parentNode.classList.remove('audio-player-playing'); | | this.parentNode.classList.remove('audio-player-playing'); |
| }; | | }; |
第52行: |
第65行: |
| button.onclick = function () { | | button.onclick = function () { |
| var a = this.firstElementChild; | | var a = this.firstElementChild; |
| + | |
| + | if (currentPlaying != a) { |
| + | currentPlaying.currentTime = currentPlaying.duration; |
| + | } |
| | | |
| if (a.paused) { | | if (a.paused) { |
| a.play(); | | a.play(); |
− | this.classList.add('audio-player-playing');
| |
− | this.classList.remove('audio-player-paused');
| |
| } | | } |
| else { | | else { |
| a.pause(); | | a.pause(); |
− | this.classList.add('audio-player-paused');
| |
− | this.classList.remove('audio-player-playing');
| |
| }; | | }; |
| }; | | }; |