Skip to content

Commit

Permalink
feat: youtube api methods general
Browse files Browse the repository at this point in the history
  • Loading branch information
biati-digital committed Sep 7, 2024
1 parent 255c7b5 commit 7ae45bf
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions packages/video/src/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export default class VideoSlide extends GLightboxPlugin {
}
}
});
playerAPI.play = () => { playerAPI.playVideo() };
playerAPI.pause = () => { playerAPI.pauseVideo() };
this.youtubePlayers.set(config.id, playerAPI);
};
});
Expand Down Expand Up @@ -266,29 +268,31 @@ export default class VideoSlide extends GLightboxPlugin {
});
return;
}
if (player?.type === 'local') {
action === 'play' ? player.api.play() : player.api.pause();
const actions = {
'play': player.api.play,
'pause': player.api.pause
}
if (player?.type === 'vimeo') {
action === 'play' ? player.api.play() : player.api.pause();
}
if (player?.type === 'youtube') {
action === 'play' ? player.api.playVideo() : player.api.pauseVideo();
if (action in actions) {
actions[action].apply(player.api);
}
}

private isVimeo(url: string): boolean {
if (url.match(/vimeo\.com\/([0-9]*)/)) {
return url.includes('vimeo.com');
}

private isYoutube(url: string): boolean {
if (url.includes('youtube.com') ||
url.includes('youtu.be') ||
url.includes('youtube-nocookie.com')
) {
return true;
}
return false;
}

private isYoutube(url: string): boolean {
if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) ||
url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/) ||
url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-zA-Z0-9\-_]+)/) ||
url.match(/(youtube\.com|youtube-nocookie\.com)\/shorts\/([a-zA-Z0-9\-_]+)/)) {
private isRegularVideo(url: string): boolean {
if (url.match(/\.(mpg|avi|webm|mov|ogv|mp4)/)) {
return true;
}
return false;
Expand All @@ -303,13 +307,6 @@ export default class VideoSlide extends GLightboxPlugin {
}).join('&');
}

private isRegularVideo(url: string): boolean {
if (url.match(/\.(mpg|avi|webm|mov|ogv|mp4)/)) {
return true;
}
return false;
}

destroy(): void {
this.players = new Map();
this.vimeoPlayers = new Map();
Expand Down

0 comments on commit 7ae45bf

Please sign in to comment.