diff options
Diffstat (limited to 'public/assets/javascripts/mx/primitives/mx.youtube.js')
| -rw-r--r-- | public/assets/javascripts/mx/primitives/mx.youtube.js | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/public/assets/javascripts/mx/primitives/mx.youtube.js b/public/assets/javascripts/mx/primitives/mx.youtube.js index b21184d..3662d7b 100644 --- a/public/assets/javascripts/mx/primitives/mx.youtube.js +++ b/public/assets/javascripts/mx/primitives/mx.youtube.js @@ -24,7 +24,7 @@ MX.Youtube = MX.Object3D.extend({ }, load: function (ops) { - var uid = 'player-' + Uid() + var uid = 'player-' + Uid () var preload = document.createElement("div") preload.id = uid preload.style.backgroundImage = "url(" + this.media.thumbnail + ")" @@ -34,6 +34,16 @@ MX.Youtube = MX.Object3D.extend({ preload.className = "preload" this.el.appendChild(preload) + // simply defer if not loaded yet + YT = YT || { + Player: function(){ + var args = arguments + setTimeout(function(){ + base.player = YT.loading ? YT.Player (args) : new YT.Player(args) + }, 300) + } + } + this.player = new YT.Player(uid, { videoId: this.media.token, width: this.width, @@ -41,7 +51,22 @@ MX.Youtube = MX.Object3D.extend({ events: { onReady: $.proxy(this.ready, this), onError: $.proxy(this.error, this), - } + onStateChange: $.proxy(this.statechange, this), + }, + playerVars: { + autohide: 1, + autoplay: 0, + disablekb: 1, + controls: 0, + enablejsapi: 1, + fs: 0, + modestbranding: 1, + iv_load_policy: 3, // no annotations + loop: 0, + showinfo: 0, + rel: 0, + wmode: 'opaque', + }, }) }, @@ -53,6 +78,24 @@ MX.Youtube = MX.Object3D.extend({ console.log("youtube error", err) }, + statechange: function(e){ + switch (e.data) { + case -1: // unstarted + break + case 0: // finished + this.finished() + break + case 1: // play + break + case 2: // pause + break + case 3: // buffering + break + case 5: // cued + break + } + }, + play: function(){ this.player.playVideo() }, @@ -61,10 +104,17 @@ MX.Youtube = MX.Object3D.extend({ this.player.pauseVideo() }, - seek: function(n){ + seek: function(n, allowSeekAhead){ + allowSeekAhead = typeof allowSeekAhead == "boolean" ? allowSeekAhead : true + this.player.seekTo(n, true) // set to false if seeking manually }, duration: function(){ + return this.player.getDuration() + }, + + finished: function(){ + console.log("youtube finished") } }) |
