YouTube IFrame API 사용시 자막 (caption) 끄기

Sukwon Yi
Sukwon Yi
Sep 1, 2018 · 2 min read

YouTube IFrame API 를 사용해서 YouTube 기능을 앱에 추가할 때, 화면 아랫쪽에 오버레이되는 자막을 표시하지 않고 싶을 때가 있습니다.

찾아보면 player parameter 중에 cc_load_policy 라는 것으로 컨트롤이 될 것처럼 보이는데, 실제로 해보면 잘 되지 않습니다... 인터넷에 보면 3으로 하면 된다 아니다 하는 얘기가 나오는데 어떤 값을 줘도 잘 안됩니다.

제가 성공한 방법은 다음과 같습니다.

  1. 플레이어의 onApiChange 이벤트 핸들러에 다음과 같이 추가합니다.
player = new YT.Player('youTubePlayerDOM', {
events: {
...
onApiChange: function(event) {
player.setOption('captions', 'track', {})
}
...
}
...
})

2. 캡션 모듈을 로딩합니다. 저는 플레이어 인스턴스를 만든 뒤에 다음과 같이 로딩해 주었습니다.

player = new YT.Player(…)
player.loadModule('captions')

위와 같이 하면 동영상 및 사용자의 자막 설정과 무관하게 자막이 표시되지 않는 것을 볼 수 있습니다.

Sukwon Yi

Written by

Sukwon Yi

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade