2022年12月28日 NBA常规赛 太阳vs灰熊 全场集锦
2022-12-28 16:36:30
event.data === YT.PlayerState.BUFFERING) {
play = false;
} else {
play = true;
}
iframe.contentWindow.postMessage(JSON.stringify({
event: 'command',
func: play ? 'playVideo' : 'pauseVideo'
}), '*');
}
// 处理进度条
function handleProgressBarChange(event) {
const progressValue = event.target.value / 100;
iframe.contentWindow.postMessage(JSON.stringify({
event: 'command',
func: 'seekTo',
args: [progressValue]
}), '*');
}
// 更新时间显示
function updateTimeDisplay() {
const currentTime = player.getCurrentTime();
const duration = player.getDuration();
timeDisplay.textContent = formatTime(currentTime) + ' / ' + formatTime(duration);
}
// 格式化时间
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const secondsLeft = Math.round(seconds % 60);
return `${minutes}:${secondsLeft < 10 ? '0' : ''}${secondsLeft}`;
}
// 添加事件监听器到播放/暂停按钮
playPauseButton.addEventListener('click', () => {
if (player) {
const state = player.getPlayerState();
handlePlayPause({ data: state });
}
});
// 处理进度条变化
progressBar.addEventListener('input', handleProgressBarChange);
// 全屏处理
function handleFullScreen() {
iframe.requestFullscreen();
}
// 添加事件监听器到全屏按钮
fullScreenButton.addEventListener('click', () => {
handleFullScreen();
});
// 启动 YouTube iFrame API 准备就绪事件处理器
window.onload = onYouTubeIframeAPIReady;
} else {
console.error('YouTube iFrame API 不可用');
}