유튜브에 컨트롤러 달기
유튜브에 재생, 일시정지, 정지 버튼 및 타이머와 트랙바를 달아 보았습니다.
https://sir.kr/g5_tip/15757 의 깔끔형으로 걸었습니다.
트랙바는 가장 심플하게 만들었는데 버튼형이나 버튼 드래그형도 시간나면 만들 생각입니다.
최종으로 생각하고 있는 것이 가운데에 온오프 토글버튼이 들어간 테두리 원형 트랙바입니다.
기타 트랙바에 몇 퍼센트 로딩이 되었는지를 감지하는 로딩바도 적용해야 하고 볼륨바 및 풀스크린 토글버튼도 만들어야 하겠지요.
[code]
<script src=https://www.youtube.com/iframe_api></script>
<script>
trackWidth = 600; // 트랙바 가로픽셀
trackHeight = 10; // 트랙바 세로픽셀
leftColor = '#ff0000'; // 트랙바 좌측 색상
rightColor = '#eeeeee'; // 트랙바 우측색상
function onYouTubeIframeAPIReady() {
divPlayer = new YT.Player('iframePlayer', { events: {'onReady': onPlayerReady} });
}
function onPlayerReady(event) {
event.target.playVideo();
}
offMode = 1;
function ytMode() {
if (arguments[0] == 'stop') divPlayer.pauseVideo(), offMode = 0;
else if (arguments[0] == 'pause') divPlayer.pauseVideo(), offMode = 1;
else divPlayer.seekTo(divPlayer.getCurrentTime() * offMode), divPlayer.playVideo(), offMode = 1;
}
function youtubeState() {
youtubeTimer = setInterval(youtubeCurrent, 500);
}
function youtubeCurrent() {
currentTimer.innerText = ('0' + Math.floor(divPlayer.getCurrentTime() / 60)).slice(-2) + ':' + ('0' + Math.floor(divPlayer.getCurrentTime() % 60)).slice(-2);
totalTimer.innerText = ('0' + Math.floor(divPlayer.getDuration() / 60)).slice(-2) + ':' + ('0' + Math.floor(divPlayer.getDuration() % 60)).slice(-2);
trackMode(divPlayer.getCurrentTime() / divPlayer.getDuration() * trackWidth);
}
youtubeState();
function barMode() {
for (var i = 0; i < trackWidth; i++) document.write("<div id=bar_" + i + " class=trackClip onclick=seekBar(" + i + ")></div>");
}
function trackMode() {
for (var i = 0; i < trackWidth; i++) this['bar_' + i].style.background = i <= arguments[0] ? leftColor : rightColor;
}
function seekBar() {
trackMode(arguments[0]);
ytMode('play');
divPlayer.seekTo(divPlayer.getDuration() * arguments[0] / trackWidth);
}
function ytLoadPlayer() {
trackBar.style.width = trackWidth + 'px';
trackBar.style.height = trackHeight + 'px';
}
document.addEventListener('DOMContentLoaded', ytLoadPlayer);
</script>
<style>
#divPlayer { position:relative; padding-bottom:56.25%; height:0px; overflow:hidden; max-width:100%; }
.normalPlayer { position:absolute; top:0px; left:0px; width:100%; height:100%; display:block; }
.cutPlayer { position:absolute; top:-50%; left:0px; width:100%; height:200%; display:block; }
.trackClip { width:1px; cursor:pointer; float:left; height:100%; }
</style>
<div style=width:800px>
<div id=divPlayer><iframe id=iframePlayer class=cutPlayer src=https://www.youtube.com/embed/VlMEGBsw6j8?autoplay=1&loop=1&playlist=VlMEGBsw6j8&enablejsapi=1 frameborder=0 allowfullscreen></iframe></div>
<br>
<span id=currentTimer style=margin-right:20px>00:00</span>
<button onclick=ytMode('play') style=cursor:pointer>PLAY</button>
<button onclick=ytMode('pause') style=cursor:pointer>PAUSE</button>
<button onclick=ytMode('stop') style=cursor:pointer>STOP</button>
<span id=totalTimer style=margin-left:20px>00:00</span>
<br><br>
<div id=trackBar style="border:1px solid #cccccc"><script>barMode()</script></div>
</div>
[/code]
----------
예제 - http://www.mediaplayer.kr/main/tip/12
댓글 9개
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4400 | ||
| 1824 |
|
4년 전 | 2739 | |
| 1823 |
|
4년 전 | 3291 | |
| 1822 | 4년 전 | 4671 | ||
| 1821 |
|
4년 전 | 3802 | |
| 1820 |
jaykjayk5
|
4년 전 | 3473 | |
| 1819 |
|
4년 전 | 5455 | |
| 1818 | 4년 전 | 2675 | ||
| 1817 | 4년 전 | 7755 | ||
| 1816 |
|
4년 전 | 5278 | |
| 1815 | 4년 전 | 4024 | ||
| 1814 | 4년 전 | 5269 | ||
| 1813 | 4년 전 | 6272 | ||
| 1812 | 4년 전 | 5968 | ||
| 1811 | 4년 전 | 4454 | ||
| 1810 | 4년 전 | 4674 | ||
| 1809 |
|
4년 전 | 3117 | |
| 1808 | 4년 전 | 3813 | ||
| 1807 | 4년 전 | 4900 | ||
| 1806 |
|
4년 전 | 7453 | |
| 1805 |
|
4년 전 | 4423 | |
| 1804 |
|
4년 전 | 3975 | |
| 1803 |
|
4년 전 | 12963 | |
| 1802 |
|
4년 전 | 9693 | |
| 1801 | 4년 전 | 5132 | ||
| 1800 |
리얼오피스
|
4년 전 | 3811 | |
| 1799 | 4년 전 | 4198 | ||
| 1798 |
만두먹고또먹고
|
4년 전 | 4149 | |
| 1797 | 4년 전 | 4517 | ||
| 1796 | 4년 전 | 3890 | ||
| 1795 |
JKWang
|
4년 전 | 4657 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기