JavaScript

[js] JS - 유튜브 동영상 (전체재생시간/현재재생시간) 체크 ※ youtube iframe (유튜브 아이프레임) 모두 재생 완료 여부 체크


유튜브 동영상 (전체재생시간/현재재생시간) 체크

 

<style>

.homzzang {

  position: relative;

  width: 100%;

  padding-bottom: 56.25%; /* 16:9 */

}

.homzzang iframe {

  position: absolute;

  width: 100%;

  height: 100%;

}

</style>

 

<div class="homzzang">

    <iframe src="https://www.youtube.com/embed/m8ndX5pz-h0?enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

</div>

 

<form action="..." method="...">

    <input id="ytb_cur" name="ytb_cur">

    <input id="ytb_tot" name="ytb_tot">

</form> 

 

<script src="https://www.youtube.com/iframe_api"></script>

<script>

function onYouTubeIframeAPIReady() {

    ytb = new YT.Player(document.querySelector(".homzzang iframe"), { "onReady": (event) => { event.target.playVideo(); } } );

    setInterval( () => {

        ytb_cur.value = Math.floor(ytb.getCurrentTime()); // 현재

        ytb_tot.value = Math.floor(ytb.getDuration()); // 전체

    }, 1000);

}

</script>

 

결과보기

PS1. 모두 시청 여부 체크: (yt_current >= yt_total-1)  (∵ 핑크색코드)

PS2. 활용: 다른 영상 재생 / 다음 부분부터 재생 / 시청 완료 회원 리스트 등

비타주리 님 (221219) https://sir.kr/g5_tip/19529


분류 제목
js JS - 3D 입체 영상 (= 입체 화면 = 이미지 파노라마 360도 회전 영상 = Image Panoram…
js JS - m3u8 ★ (동영상재생 + 플레이어 다운 + 동영상다운로드 : 엠삼유팔 = 엠쓰리유팔 )
js JS - 이전페이지 보내기 (= 기존페이지로 돌아가기) 3가지방법
js JS - 각종 게임 무료다운로드 주소 좌표 (= 게임다운좌표)
js JS - 서브도메인 입력 후 해당 주소로 이동
js JS - 예약어 (= 변수명・라벨명・함수명 등으로 사용 불가능한 단어)
js JS - play(), pause() 메서드 - 동영상 재생/멈춤. (= play메서드, pause메서드 =…
js JS - 입력값 길이 제한 후, 경고창 띄우기
js JS - 눈 내리는 효과 (Snowflakes effect)
js JS - CSS 다크모드 토글 (Dark Mode Toggle) ※ 클래스 상호 대체/변환
js JS - 스크롤 정도/위치 진행바 표시기 (Scroll Indicator Bar)
js JS - 숫자 (카운팅/변동) 애니 효과
js JS - select() 메서드 - INPUT 텍스트 내용 선택 (= select메서드 = 실렉트메서드|셀렉…
js JS - 특정 배수만 입력 허용
js JS - 자동 세미콜론 삽입 (ASI : Automatic semicolon insertion) 적용되는 구…
2/5
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱닷컴 PC버전 로그인