2017-02-23
HTML5의 VIDEO태그의 컨트롤러들은 사용자가 임의로 조정이 가능하다.
아래는 그런 활용에 대한 글이 있는 링크이다.
링크: http://blog.teamtreehouse.com/building-custom-controls-for-html5-videos

위 링크에 있는 예제를 한글로 바꾸어 보았다.
<div id="video-container">
  <video id="video" width="640" height="365">
    <source src="../../post_inc/video/test_video1.mp4" type="video/mp4">
    <p>
	  해당 브라우저는 HTML5 video태그를 지원하지 않습니다..
    </p>
  </video>
  <!-- Video Controls -->
  <div id="video-controls">
    <button type="button" id="play-pause">재생</button>
    <input type="range" id="seek-bar" value="0">
    <button type="button" id="mute">음소거</button>
    <input type="range" id="volume-bar" min="0" max="1" step="0.1" value="1">
    <button type="button" id="full-screen">전체화면</button>
  </div>
</div>

<script>
window.onload = function() {

	// Video
	var video = document.getElementById("video");

	// Buttons
	var playButton = document.getElementById("play-pause");
	var muteButton = document.getElementById("mute");
	var fullScreenButton = document.getElementById("full-screen");

	// Sliders
	var seekBar = document.getElementById("seek-bar");
	var volumeBar = document.getElementById("volume-bar");

	// 재생/일시정지 기능
	playButton.addEventListener("click", function() {
	  if (video.paused == true) {
		// Play the video
		video.play();

		// Update the button text to 'Pause'
		playButton.innerHTML = "일시정지";
	  } else {
		// Pause the video
		video.pause();

		// Update the button text to 'Play'
		playButton.innerHTML = "재생";
	  }
	});


	// 음소거 기능
	muteButton.addEventListener("click", function() {
	  if (video.muted == false) {
		// Mute the video
		video.muted = true;

		// Update the button text
		muteButton.innerHTML = "소리켜기";
	  } else {
		// Unmute the video
		video.muted = false;

		// Update the button text
		muteButton.innerHTML = "음소거";
	  }
	});

	// 전체화면 기능
	fullScreenButton.addEventListener("click", function() {
	  if (video.requestFullscreen) {
		video.requestFullscreen();
	  } else if (video.mozRequestFullScreen) {
		video.mozRequestFullScreen(); // Firefox
	  } else if (video.webkitRequestFullscreen) {
		video.webkitRequestFullscreen(); // Chrome and Safari
	  }
	});


	// 재생바가 있는 위치로 화면 이동
	seekBar.addEventListener("change", function() {
	  // Calculate the new time
	  var time = video.duration * (seekBar.value / 100);

	  // Update the video time
	  video.currentTime = time;
	});


	// 재생시간에 따른 재생바 이동
	video.addEventListener("timeupdate", function() {
	  // Calculate the slider value
	  var value = (100 / video.duration) * video.currentTime;

	  // Update the slider value
	  seekBar.value = value;
	});

	// 재생바 드래그하려고 클릭시에 동영상 정지
	seekBar.addEventListener("mousedown", function() {
	  video.pause();
	});

	// 재생바 클릭 후에 동영상 재생
	seekBar.addEventListener("mouseup", function() {
	  video.play();
	});

	// 볼륨바 기능
	volumeBar.addEventListener("change", function() {
	  // Update the video volume
	  video.volume = volumeBar.value;
	});

}
</script>