summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx/primitives/mx.video.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/mx/primitives/mx.video.js')
-rw-r--r--public/assets/javascripts/mx/primitives/mx.video.js99
1 files changed, 58 insertions, 41 deletions
diff --git a/public/assets/javascripts/mx/primitives/mx.video.js b/public/assets/javascripts/mx/primitives/mx.video.js
index 1b17994..2fbf6be 100644
--- a/public/assets/javascripts/mx/primitives/mx.video.js
+++ b/public/assets/javascripts/mx/primitives/mx.video.js
@@ -4,52 +4,69 @@ MX.Video = MX.Object3D.extend({
this.type = "Video"
- var layer = this
- layer.width = ops.width
- layer.height = ops.height
- layer.x = ops.x || 0
- layer.y = ops.y || 0
- layer.z = ops.z || 0
- layer.rotationX = ops.rotationX || 0
- layer.rotationY = ops.rotationY || 0
- layer.rotationZ = ops.rotationZ || 0
- layer.scale = ops.scale || 1
- layer.backface = ops.backface || false
- layer.media = ops.media
- layer.el.classList.add('video')
-
- if (layer.backface) {
- layer.el.classList.add("backface-visible")
- }
-
- if (ops.src) {
- this.load(ops)
- }
+ this.media = ops.media
+ this.width = ops.media.width
+ this.height = ops.media.height
+ this.x = ops.x || 0
+ this.y = ops.y || 0
+ this.z = ops.z || 0
+ this.rotationX = ops.rotationX || 0
+ this.rotationY = ops.rotationY || 0
+ this.rotationZ = ops.rotationZ || 0
+ this.scale = ops.scale || 1
+ this.backface = ops.backface || false
- if (ops.className) {
- layer.el.classList.add(ops.className)
- }
- layer.el.style.backgroundRepeat = 'no-repeat'
+ ops.className && this.el.classList.add(ops.className)
+ this.backface && this.el.classList.add("backface-visible")
+ this.el.classList.add("video")
+
+ this.load()
},
load: function(ops){
- var layer = this
-
- var video = document.createElement('video')
- video.addEventListener("loadedmetadata", function(){
- if (ops.autoplay) {
- video.play()
- }
- else {
- video.currentTime = video.duration / 3
- }
- })
- video.width = layer.width
- video.height = layer.height
- video.src = ops.src
- video.load()
+ this.player = document.createElement('video')
+ this.player.addEventListener("loadedmetadata", $.proxy(this.ready, this))
+ this.player.addEventListener("error", $.proxy(this.error, this))
+ this.player.width = this.width
+ this.player.height = this.height
+ this.player.src = this.media.url
+ this.player.load()
- this.el.appendChild(video)
+ this.el.appendChild(this.player)
+ },
+
+ ready: function(){
+ if (this.media.autoplay) {
+ video.play()
+ }
+ else {
+ video.currentTime = video.duration / 3
+ }
+ },
+
+ error: function(err){
+ console.log("video error", err)
},
+
+ play: function(){
+ this.player.play()
+ },
+
+ pause: function(){
+ this.player.pause()
+ },
+
+ seek: function(n){
+ this.player.currentTime = n
+ },
+
+ duration: function(){
+ return this.player.duration
+ },
+
+ finished: function(){
+ console.log("video finished")
+ },
+
})