Template:AudioPlayer: Difference between revisions
From Tuyin Archives
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
<html> | <html> | ||
<script> | <script> | ||
var | var audio{{{1}}} = new Audio('https://tuyin.online/images/{{{1}}}'); | ||
var | var isPlaying{{{1}}} = false; | ||
function | function togglePlay{{{1}}}() { | ||
var button = document.getElementById( | var button = document.getElementById('playBtn{{{1}}}'); | ||
if ( | if (isPlaying{{{1}}}) { | ||
audio{{{1}}}.pause(); | |||
button.innerHTML = '▶️'; | button.innerHTML = '▶️'; | ||
isPlaying{{{1}}} = false; | |||
} else { | } else { | ||
audio{{{1}}}.play(); | |||
button.innerHTML = '⏸️'; | button.innerHTML = '⏸️'; | ||
isPlaying{{{1}}} = true; | |||
} | } | ||
} | } | ||
audio{{{1}}}.addEventListener('timeupdate', function() { | |||
var progress = document.getElementById( | var progress = document.getElementById('progress{{{1}}}'); | ||
var percentage = (audio{{{1}}}.currentTime / audio{{{1}}}.duration) * 100; | |||
progress.style.width = percentage + '%'; | |||
}); | }); | ||
audio{{{1}}}.addEventListener('ended', function() { | |||
document.getElementById('playBtn{{{1}}}').innerHTML = '▶️'; | |||
isPlaying{{{1}}} = false; | |||
document.getElementById('progress{{{1}}}').style.width = '0%'; | |||
}); | }); | ||
</script> | </script> | ||
| Line 38: | Line 32: | ||
<div style="display: inline-flex; align-items: center; gap: 12px;"> | <div style="display: inline-flex; align-items: center; gap: 12px;"> | ||
<div style="border: 1px solid #8B7355; padding: 8px; display: inline-block; border-radius: 4px; background-color: #F5F0E8; width: 200px;"> | <div style="border: 1px solid #8B7355; padding: 8px; display: inline-block; border-radius: 4px; background-color: #F5F0E8; width: 200px;"> | ||
<button onclick=" | <button id="playBtn{{{1}}}" onclick="togglePlay{{{1}}}()" style="padding: 4px 8px; margin-right: 8px; font-size: 12px; border: 1px solid #8B7355; background: #D4C4A8; color: #5D4E37;">▶️</button> | ||
<div style="display: inline-block; width: 120px; height: 6px; background-color: #D4C4A8; border-radius: 3px; vertical-align: middle;"> | <div style="display: inline-block; width: 120px; height: 6px; background-color: #D4C4A8; border-radius: 3px; vertical-align: middle;"> | ||
<div style="height: 100%; background-color: #8B7355; border-radius: 3px; width: 0%; transition: width 0.1s;"></div> | <div id="progress{{{1}}}" style="height: 100%; background-color: #8B7355; border-radius: 3px; width: 0%; transition: width 0.1s;"></div> | ||
</div> | </div> | ||
</div> | </div> | ||
<span style="color: #8B7355; font-style: italic;">{{{2|Audio File}}}</span> | <span style="color: #8B7355; font-style: italic;">{{{2|Audio File}}}</span> | ||
</div> | </div> | ||
</html> | </html> | ||
Revision as of 19:20, 23 July 2025
