๐ ์ค๋์ค ์ฌ์
let track = new Audio();
let flag = 0; // flag๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ์ ์ค์ธ ์ค๋์ค ์์ผ๋ฉด ์ ์ง
const playVoice = (audioSrc) =>{
track.src = audioSrc;
console.log(track.paused)
if(flag === 0){
flag = 1;
playAudio();
}else{
flag = 0;
stopAudio()
}
}
const playAudio = () => {
track.play();
track.paused = false
iconAnimation("play");
}
const stopAudio = () => {
track.pause();
track.currentTime = 0;
iconAnimation("stop");
}
track.addEventListener('ended', function() {
iconAnimation();
});
const iconVoice = document.querySelectorAll('.icon_voice');
const iconAnimation = (status) =>{
iconVoice.forEach(function(icon){
if(status === "play"){
icon.classList.add('play');
}else{
icon.classList.remove('play');
}
})
}
new Audio(filePath) : ์ค๋์ค ์์ฑ์
new Audio(url)
audioObject.play() : ์ค๋์ค ์ฌ์ ๋ฉ์๋
audioObject.pause() : ์ค๋์ค ์ ์ง ๋ฉ์๋
const playAudio = () => {
track.play(); // ์ค๋์ค ํ๋ ์ด
track.paused = false; // "์ ์ง"์์ฑ ๊ฐ false
iconAnimation("play"); // ํ๋ ์ด ์ํ๋ก ์คํ์ผ ๋ณ๊ฒฝํ๋ ํจ์
}
const stopAudio = () => {
track.pause(); // ์ค๋์ค์ ์ง
track.currentTime = 0; // ์ค๋์ค ์ฌ์์๊ฐ์ 0์ผ๋ก ๋ณ๊ฒฝ
iconAnimation("stop"); // ์ ์ง ์ํ๋ก ์คํ์ผ ๋ณ๊ฒฝํ๋ ํจ์
}
๋ฐ์ํ
'D.evelop > MarkUp' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[XAML] Label ์ปจํธ๋กค (0) | 2023.12.14 |
---|---|
[HTML]canvas ์ฌ์ฉ๋ฒ - ๊ธฐ๋ณธ (rect, path, arc) (0) | 2023.05.27 |
[HTML] redirect <meta http-equiv="refresh"/>๋ก ํด๊ฒฐํ ์ฌ๋ก (0) | 2022.06.15 |
[HTML] aํ๊ทธ link์ onclick์ ํตํ ๋งํฌ ์ด๋ (with C#) (0) | 2022.06.15 |
videoํ๊ทธ - ์๋ ์ฌ์ autoplay์ ๋ํ ๋ฐฉ๋ฒ๊ณผ ์๊ฐ (3) | 2022.03.15 |
๋๊ธ