// Wait for the DOM to be ready, then wire up the Vimeo player.
$(function () {
"use strict";
// Grab elements.
const iframeEl = document.getElementById("vimeoPlayer");
const $toggleBtn = $("#pauseBtn");
const $posterOverlay = $("#posterOverlay");
const $posterImg = $("#posterImg");
// Wrap the existing iframe with the Vimeo Player SDK.
const player = new Vimeo.Player(iframeEl);
// Local fallback state (used only if getPaused() fails).
let lastKnownPaused = false;
// Update the button UI to match player state.
function renderButton(paused) {
lastKnownPaused = paused;
$toggleBtn.text(paused ? "Play" : "Pause");
// For toggle buttons, aria-pressed should reflect the active state.
// Here we treat "pressed" as "playing".
$toggleBtn.attr("aria-pressed", paused ? "false" : "true");
}
// Sync initial label once the player is ready.
function syncButtonWithPlayer() {
return player
.getPaused()
.then(renderButton)
.catch(function () {
// If we can't read state, default to showing "Pause".
renderButton(false);
});
}
// Show a poster thumbnail while the iframe/player is loading.
// We fetch a thumbnail from Vimeo's oEmbed endpoint using the video id.
(function initPoster() {
const src = String($(iframeEl).attr("src") || "");
const match = src.match(/\/video\/(\d+)/);
const videoId = match ? match[1] : null;
if (!videoId) {
// Can't determine the video id; keep the black overlay as a simple fallback.
$posterOverlay.addClass("is-visible");
return;
}
const oEmbedUrl = "https://vimeo.com/api/oembed.json";
const videoUrl = "https://vimeo.com/" + videoId;
$.getJSON(oEmbedUrl, { url: videoUrl })
.done(function (data) {
if (data && data.thumbnail_url) {
$posterImg.attr("src",...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.