summaryrefslogtreecommitdiff
path: root/public/js/mx/mx.video.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-04 21:56:04 -0400
committerJules Laplace <jules@okfoc.us>2015-08-04 21:56:04 -0400
commit927b6670e2da26bf1823efd49462c8bfb8317cb7 (patch)
tree3d89c7683a0fb69ab2aee5a29639f69bc9cccbf2 /public/js/mx/mx.video.js
parent0b47720bad6a9c3b3447da97a89b91a1f8ab7d71 (diff)
mx libs
Diffstat (limited to 'public/js/mx/mx.video.js')
-rw-r--r--public/js/mx/mx.video.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/public/js/mx/mx.video.js b/public/js/mx/mx.video.js
new file mode 100644
index 0000000..53ccf2e
--- /dev/null
+++ b/public/js/mx/mx.video.js
@@ -0,0 +1,118 @@
+MX.Video = MX.Object3D.extend({
+
+ init: function (ops) {
+
+ this.type = "Video"
+
+ 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
+
+ ops.className && this.el.classList.add(ops.className)
+ this.backface && this.el.classList.add("backface-visible")
+ this.el.classList.add("video")
+ this.el.classList.add("mx-scenery")
+ this.paused = !! this.media.autoplay
+ this.playing = false
+ this.muted = app.muted || !! this.media.mute
+ },
+
+ load: function(ops){
+ this.paused = true
+
+ this.player = document.createElement('video')
+ this.player.addEventListener("loadedmetadata", this.ready.bind(this))
+ this.player.addEventListener("error", this.error.bind(this))
+ this.player.addEventListener("ended", this.finished.bind(this))
+ this.player.width = "100%"
+ this.player.height = "100%"
+ this.player.src = this.media.url
+ this.player.load()
+
+ this.el.appendChild(this.player)
+ },
+
+ ready: function(){
+ this.seek( this.media.keyframe || 0 )
+
+ if (this.media.mute) {
+ this.mute()
+ }
+ else {
+ this.unmute()
+ }
+
+ if (this.media.autoplay) {
+ this.play()
+ }
+ },
+
+ error: function(err){
+ console.log("video error", err)
+ },
+
+ play: function(){
+ this.paused = false
+ this.playing = true
+ this.player.play()
+ },
+
+ pause: function(){
+ this.paused = true
+ this.playing = false
+ this.player.pause()
+ },
+
+ seek: function(n){
+ if (n < 1) {
+ n = n * this.duration()
+ }
+ this.player.currentTime = n
+ },
+
+ mute: function(){
+ this.player.muted = true
+ this.player.volume = 0
+ this.muted = true
+ },
+
+ unmute: function(){
+ this.player.muted = false
+ this.player.volume = 0.8
+ this.muted = false
+ },
+
+ setVolume: function(n){
+ if (this.muted || ! this.player) return
+ this.player.volume = n
+ },
+
+ setLoop: function(state){
+ this.media.loop = state
+ },
+
+ duration: function(){
+ return this.player.duration
+ },
+
+ finished: function(){
+ console.log("video finished")
+ if (this.media.loop) {
+ this.seek(0)
+ this.play()
+ }
+ else if (this.bound) {
+ $(".playButton").removeClass('playing')
+ }
+ },
+
+
+})