오디오에 타이머 붙이기
https://sir.kr/g5_tip/18697 의 연속팁입니다.
span 의 위치와 css 는 알아서...
차례대로 재생시간, 토탈시간, 남은시간의 순입니다.
쓰고 싶지 않은 span, 예를 들어서 남은시간 타이머가 필요 없으면
restTimer 이라는 span 을 삭제해 버리면 되겠습니다.
이것이 가능한 이유는 아래의 형식으로 이프문을 걸어주었기 때문입니다.
if (typeof restTimer != "undefined") --- 만일 restTimer 가 존재한다면
[code]
<audio id=myAudio src="https://blog.kakaocdn.net/dn/c4djm7/btrET8xkkOc/89VxkXWg4wSOrnwWPKsJqK/tfile.mp3" loop></audio>
<img id=myImg style=cursor:pointer;display:block>
<span id=currentTimer>00:00</span>
<span id=totalTimer>00:00</span>
<span id=restTimer>00:00</span>
<script>
onImg = "https://blog.kakaocdn.net/dn/wZ0tS/btrEOGJvjIE/8dv2ALyvIwk7cGS4p1Pkd0/img.png";
offImg = "https://blog.kakaocdn.net/dn/qrTkp/btrEN9SGsPz/0ztiKLUfAkLnmJON7nwc91/img.png";
function playAudio() {
myImg.src = offImg;
myAudio.play();
}
function pauseAudio() {
myImg.src = onImg;
myAudio.pause();
}
myImg.onclick = function() {
myAudio.paused ? playAudio() : pauseAudio();
}
myImg.src = onImg;
function trackMode() {
if (myAudio.currentTime > 0) {
if (typeof currentTimer != "undefined") currentTimer.innerText = ("0" + Math.floor(myAudio.currentTime / 60)).slice(-2) + ":" + ("0" + Math.floor(myAudio.currentTime % 60)).slice(-2);
if (typeof totalTimer != "undefined") totalTimer.innerText = ("0" + Math.floor(myAudio.duration / 60)).slice(-2) + ":" + ("0" + Math.floor(myAudio.duration % 60)).slice(-2);
if (typeof restTimer != "undefined") restTimer.innerText = ("0" + Math.floor((myAudio.duration - myAudio.currentTime) / 60)).slice(-2) + ":" + ("0" + Math.floor((myAudio.duration - myAudio.currentTime) % 60)).slice(-2);
}
}
setInterval(trackMode, 500);
</script>
[/code]
댓글 6개
리자님 레이다망에 안 걸릴 지 모르겠네요.ㅜㅠ
따지고 보면 그누팁이라기 보다는 일반팁이라서요.
트랙바까지만 올릴 생각입니다.ㅋ
초보자들은 게시판에 적용하기가 어려울수도 있어서 게시판에 적용해보았습니다.
https://sir.kr/g5_tip/18802
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4420 | ||
| 2154 | 3년 전 | 3228 | ||
| 2153 | 3년 전 | 2723 | ||
| 2152 |
|
3년 전 | 2592 | |
| 2151 | 3년 전 | 2228 | ||
| 2150 | 3년 전 | 2611 | ||
| 2149 | 3년 전 | 4229 | ||
| 2148 | 3년 전 | 3500 | ||
| 2147 | 3년 전 | 1910 | ||
| 2146 | 3년 전 | 2889 | ||
| 2145 | 3년 전 | 4021 | ||
| 2144 | 3년 전 | 2936 | ||
| 2143 | 3년 전 | 2302 | ||
| 2142 |
welcome
|
3년 전 | 2090 | |
| 2141 | 3년 전 | 2480 | ||
| 2140 |
|
3년 전 | 3481 | |
| 2139 |
|
3년 전 | 3229 | |
| 2138 | 3년 전 | 3248 | ||
| 2137 | 3년 전 | 3013 | ||
| 2136 | 3년 전 | 3134 | ||
| 2135 | 3년 전 | 3746 | ||
| 2134 | 3년 전 | 3305 | ||
| 2133 | 3년 전 | 3463 | ||
| 2132 |
|
3년 전 | 5320 | |
| 2131 | 3년 전 | 2359 | ||
| 2130 | 3년 전 | 3952 | ||
| 2129 |
|
3년 전 | 2947 | |
| 2128 | 3년 전 | 2978 | ||
| 2127 | 3년 전 | 4296 | ||
| 2126 | 3년 전 | 2554 | ||
| 2125 | 3년 전 | 2706 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기