From 5e934bb274c66a1a007a338e26194b49592801bb Mon Sep 17 00:00:00 2001 From: "Stringer.Sean" Date: Thu, 12 Jun 2014 16:18:49 -0700 Subject: [PATCH 1/2] Video working in DOM and Canvas --- lime/demos/tests/run.htm | 4 +- lime/demos/tests/video.js | 67 ++++++++ lime/demos/tests/video2.js | 67 ++++++++ lime/src/video.js | 327 +++++++++++++++++++++++++++++++++++++ 4 files changed, 464 insertions(+), 1 deletion(-) create mode 100644 lime/demos/tests/video.js create mode 100644 lime/demos/tests/video2.js create mode 100644 lime/src/video.js diff --git a/lime/demos/tests/run.htm b/lime/demos/tests/run.htm index 06a8f7b3..80a06d61 100644 --- a/lime/demos/tests/run.htm +++ b/lime/demos/tests/run.htm @@ -30,7 +30,9 @@ 'scroll', 'stroke', 'tiled1', 'tiled2', 'tiled3', - 'transitions1' + 'transitions1', + 'video', + 'video2' ].sort(); for(var i=0;i<_allDemos.length;i++){ diff --git a/lime/demos/tests/video.js b/lime/demos/tests/video.js new file mode 100644 index 00000000..460ab601 --- /dev/null +++ b/lime/demos/tests/video.js @@ -0,0 +1,67 @@ +goog.provide('test.video'); + + +goog.require('lime'); +goog.require('lime.Video'); + +goog.require('lime.Director'); +goog.require('lime.Label'); + +goog.require('lime.Layer'); +goog.require('lime.Scene'); + +goog.require('lime.Sprite'); +goog.require('lime.Circle'); + +goog.require('lime.animation.ScaleTo'); +goog.require('lime.animation.MoveTo'); +goog.require('lime.animation.Loop'); + + +test.WIDTH = 600; +test.HEIGHT = 400; + + +test.start = function() { + + //director + test.director = new lime.Director(document.body, test.WIDTH, test.HEIGHT); + test.director.makeMobileWebAppCapable(); + + + var videoscene = new lime.Scene; + + var layer = (new lime.Layer).setSize(test.WIDTH, test.HEIGHT).setPosition(0, 0); + videoscene.appendChild(layer); + + var video = new lime.Video().setSize(320, 240).setAnchorPoint(0,0).setVideoUrl('assets/eye_of_beholder_intro.mp4'); + + //layer.appendChild(video); + + + var sprite = new lime.Sprite(); + + sprite.appendChild(video); + + var ch1 = new lime.Circle().setSize(30, 30).setPosition(100, 100).setFill('#c00'); + sprite.appendChild(ch1); + + var ch2 = new lime.Circle().setSize(30, 30).setPosition(150, 100).setFill('#c00'); + sprite.appendChild(ch2); + + var ch3 = new lime.Circle().setSize(30, 30).setPosition(200, 100).setFill('#c00'); + sprite.appendChild(ch3); + + layer.appendChild(sprite); + + goog.events.listen(video, ['VideoCanPlay', 'VideoCanPlayThrough'], function () { + video.playVideo(); + }, false, this); + + // set active scene + test.director.replaceScene(videoscene); + + +}; + +goog.exportSymbol('test.start', test.start); diff --git a/lime/demos/tests/video2.js b/lime/demos/tests/video2.js new file mode 100644 index 00000000..1ccd5ff7 --- /dev/null +++ b/lime/demos/tests/video2.js @@ -0,0 +1,67 @@ +goog.provide('test.video2'); + + +goog.require('lime'); +goog.require('lime.Video'); + +goog.require('lime.Director'); +goog.require('lime.Label'); + +goog.require('lime.Layer'); +goog.require('lime.Scene'); + +goog.require('lime.Sprite'); +goog.require('lime.Circle'); + +goog.require('lime.animation.ScaleTo'); +goog.require('lime.animation.MoveTo'); +goog.require('lime.animation.Loop'); + + +test.WIDTH = 600; +test.HEIGHT = 400; + + +test.start = function() { + + //director + test.director = new lime.Director(document.body, test.WIDTH, test.HEIGHT); + test.director.makeMobileWebAppCapable(); + + + var videoscene = new lime.Scene; + + var layer = (new lime.Layer).setSize(test.WIDTH, test.HEIGHT).setPosition(0, 0).setRenderer(lime.Renderer.CANVAS); + videoscene.appendChild(layer); + + var video = new lime.Video().setSize(320, 240).setAnchorPoint(0.5,0.5).setPosition(0,160).setVideoUrl('assets/eye_of_beholder_intro.mp4'); + + layer.appendChild(video); + + + var sprite = new lime.Sprite().setRenderer(lime.Renderer.CANVAS); + + sprite.appendChild(video); + + var ch1 = new lime.Circle().setSize(30, 30).setPosition(0, 160).setFill('#c00'); + sprite.appendChild(ch1); + + var ch2 = new lime.Circle().setSize(30, 30).setPosition(150, 100).setFill('#c00'); + sprite.appendChild(ch2); + + var ch3 = new lime.Circle().setSize(30, 30).setPosition(200, 100).setFill('#c00'); + sprite.appendChild(ch3); + + layer.appendChild(sprite); + + goog.events.listen(video, ['VideoCanPlay', 'VideoCanPlayThrough'], function () { + video.playVideo(); + }, false, this); + + // set active scene + test.director.replaceScene(videoscene); + + +}; + +goog.exportSymbol('test.start', test.start); diff --git a/lime/src/video.js b/lime/src/video.js new file mode 100644 index 00000000..7708dda1 --- /dev/null +++ b/lime/src/video.js @@ -0,0 +1,327 @@ +goog.provide('lime.Video'); +goog.provide('lime.Renderer.DOM.VIDEO'); +goog.provide('lime.Renderer.CANVAS.VIDEO'); + +goog.require('lime.Node'); +goog.require('goog.dom'); + + +lime.Video = function () { + goog.base(this); + + this.url_ = null; + this.videoElement_ = null; + this.isPlaying_ = false; + this._urlIsDirty = false; +}; + +goog.inherits(lime.Video, lime.Node); + +lime.Video.prototype.id = 'video'; + +lime.Video.prototype.setVideoUrl = function (url) { + this.url_ = url; + this._urlIsDirty = true; + + this.setDirty(lime.Dirty.CONTENT, 0); + return this; +}; + +lime.Video.prototype.getVideoUrl = function () { + return this.url_; +}; + +lime.Video.prototype.playVideo = function () { + this._shouldPlayNextFrame = true; + this.setDirty(lime.Dirty.CONTENT, 0); +}; + +lime.Video.prototype.loadVideo_ = function () { + console.log("VIDEO - PLAYING VIDEO"); + + this.makeVideoElement_(); +}; + +lime.Video.prototype.makeVideoElement_ = function () { + + if (!this.videoElement_) { + this.videoElement_ = goog.dom.htmlToDocumentFragment('