Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to player.js (Vimeo) #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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