Skip to content

Commit

Permalink
Migrate to player.js (Vimeo)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoftCreatR authored Sep 22, 2022
1 parent beddb39 commit 3a6cbac
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions js/blueimp-gallery-vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// The URL for the Vimeo video player, can be extended with custom parameters:
// https://developer.vimeo.com/player/embedding
vimeoPlayerUrl:
'https://player.vimeo.com/video/VIDEO_ID?api=1&player_id=PLAYER_ID',
'https://player.vimeo.com/video/VIDEO_ID',
// The prefix for the Vimeo video player ID:
vimeoPlayerIdPrefix: 'vimeo-player-',
// Require a click on the native Vimeo player for the initial playback:
Expand All @@ -62,7 +62,7 @@

loadAPI: function () {
var that = this
var apiUrl = 'https://f.vimeocdn.com/js/froogaloop2.min.js'
var apiUrl = 'https://player.vimeo.com/api/player.js'
var scriptTags = document.getElementsByTagName('script')
var i = scriptTags.length
var scriptTag
Expand Down Expand Up @@ -98,14 +98,14 @@
onReady: function () {
var that = this
this.ready = true
this.player.addEvent('play', function () {
this.player.on('play', function () {
that.hasPlayed = true
that.onPlaying()
})
this.player.addEvent('pause', function () {
this.player.on('pause', function () {
that.onPause()
})
this.player.addEvent('finish', function () {
this.player.on('finish', function () {
that.onPause()
})
if (this.playOnReady) {
Expand All @@ -129,7 +129,6 @@
var iframe = document.createElement('iframe')
iframe.src = this.url
.replace('VIDEO_ID', this.videoId)
.replace('PLAYER_ID', this.playerId)
iframe.id = this.playerId
iframe.allow = 'autoplay'
this.element.parentNode.replaceChild(iframe, this.element)
Expand All @@ -155,16 +154,18 @@
// the video playback:
this.onPlaying()
} else {
this.player.api('play')
this.player.play().catch(function(error) {
console.error('error playing the video:', error.name)
})
}
} else {
this.playOnReady = true
if (!window.$f) {
if (typeof Vimeo === "undefined") {
this.loadAPI()
} else if (!this.player) {
this.insertIframe()
this.player = $f(this.element)
this.player.addEvent('ready', function () {
this.player = new Vimeo.Player(this.element)
this.player.ready().then(function() {
that.onReady()
})
}
Expand All @@ -173,7 +174,7 @@

pause: function () {
if (this.ready) {
this.player.api('pause')
this.player.pause()
} else if (this.playStatus) {
delete this.playOnReady
this.listeners.pause()
Expand Down

0 comments on commit 3a6cbac

Please sign in to comment.