Learn how to integrate Lovable with Vimeo easily. Follow our step-by-step guide to connect your accounts and boost your video workflow seamlessly.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
In your Lovable project, open the main HTML file (often named index.html). Locate the <head>
section and add the following script tag before the closing </head>
tag. This script loads Vimeo’s Player API from its CDN, so you do not need a terminal to install dependencies.
<script src="https://player.vimeo.com/api/player.js"></script>
Make sure to save your changes.
Inside your project’s source folder (commonly named src
), create a new TypeScript file called vimeoIntegration.ts
. In this file, add the following code. This class wraps Vimeo’s player functionality and provides methods to play and pause the video.
declare var Vimeo: any;
export class VimeoIntegration {
private player: any;
constructor(elementId: string, videoId: number) {
// Configure player options.
const options = {
id: videoId,
width: 640
};
// Initialize Vimeo player on the specified element.
this.player = new Vimeo.Player(elementId, options);
// Example event: Log when the video starts playing.
this.player.on('play', () => {
console.log('Video is playing.');
});
}
// Method to play the video.
public playVideo(): void {
this.player.play().catch((error: any) => {
console.error('Error playing the video:', error);
});
}
// Method to pause the video.
public pauseVideo(): void {
this.player.pause().catch((error: any) => {
console.error('Error pausing the video:', error);
});
}
}
Save the file when finished.
In your main HTML file (index.html), identify where you want the Vimeo video to appear. Add a new <div>
element with a unique identifier. For example, place this code within the <body>
section:
<div id="vimeo-player"></div>
This container will be used by the Vimeo player.
Locate your project’s main TypeScript file (for example, main.ts
) within the src
folder. In this file, import the VimeoIntegration class and instantiate it using the container’s ID and your Vimeo video ID. Add the following code snippet in an appropriate section of your main file:
import { VimeoIntegration } from './vimeoIntegration';
// Replace 123456789 with your actual Vimeo video ID.
const videoId = 123456789;
const videoContainerId = 'vimeo-player';
// Initialize the Vimeo player.
const vimeoPlayer = new VimeoIntegration(videoContainerId, videoId);
// Example usage: Play the video after a short delay.
setTimeout(() => {
vimeoPlayer.playVideo();
}, 2000);
Save your changes.
vimeoIntegration.ts
file in your source folder with the provided code.vimeo-player
exists in your HTML, as this is where the Vimeo video will render.With these changes, your Lovable project is now integrated with Vimeo using TypeScript. The player will load your Vimeo video in the designated container, and you can control playback through the methods provided in the VimeoIntegration class.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.