| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,6 +76,7 @@ | |||
| 76 | 76 | void setVideo ( Video v ) | |
| 77 | 77 | { | |
| 78 | 78 | video = v; | |
| 79 | + console.log( v ); | ||
| 79 | 80 | } | |
| 80 | 81 | ||
| 81 | 82 | /* make Processing understand the HTMLVideoElement */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ window.onload = function () { | |||
| 3 | 3 | video['loop'] = true; | |
| 4 | 4 | ||
| 5 | 5 | function tryFindSketch () { | |
| 6 | - var sketch = Processing.instances[0]; | ||
| 6 | + var sketch = Processing.getInstanceById(getProcessingSketchID()); | ||
| 7 | 7 | if ( sketch == undefined ) | |
| 8 | 8 | return setTimeout(tryFindSketch, 200); // retry in 0.2 secs | |
| 9 | 9 | ||
@@ -16,7 +16,7 @@ window.onload = function () { | |||
| 16 | 16 | ||
| 17 | 17 | (function( s, v ){ | |
| 18 | 18 | var tryAddVideo = function () { | |
| 19 | - if ( v.readyState > 0 ) { | ||
| 19 | + if ( v.readyState > 2 ) { | ||
| 20 | 20 | s.setVideo(v); | |
| 21 | 21 | } else { | |
| 22 | 22 | setTimeout(tryAddVideo, 200); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,3 @@ | |||
| 1 | - /* @pjs transparent=true; */ | ||
| 2 | - | ||
| 3 | 1 | /** | |
| 4 | 2 | * <p>This example shows you how to use video with a transparency | |
| 5 | 3 | * which currently is not natively supported by web video formats (H264 / OGV).</p> | |
@@ -44,7 +42,13 @@ | |||
| 44 | 42 | PImage frame = video.getFrame(); | |
| 45 | 43 | PImage rgbImage = frame.get(frame.width/2,0,frame.width/2,frame.height); | |
| 46 | 44 | PImage maskImage = frame.get(0,0,frame.width/2,frame.height); | |
| 47 | - rgbImage.mask(maskImage); | ||
| 45 | + rgbImage.loadPixels(); | ||
| 46 | + maskImage.loadPixels(); | ||
| 47 | + for ( int i = 0; i < rgbImage.pixels.length; i++ ) | ||
| 48 | + { | ||
| 49 | + rgbImage.pixels[i] = (rgbImage.pixels[i] & 0x00FFFFFF) + ((maskImage.pixels[i] & 0xFF) << 24); | ||
| 50 | + } | ||
| 51 | + rgbImage.updatePixels(); | ||
| 48 | 52 | image( rgbImage, width/2-rgbImage.width/2, 0 ); | |
| 49 | 53 | } | |
| 50 | 54 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ window.onload = function () { | |||
| 4 | 4 | ||
| 5 | 5 | // try to find the Processing sketch instance, or retry | |
| 6 | 6 | function tryFindSketch () { | |
| 7 | - var sketch = Processing.instances[0]; | ||
| 7 | + var sketch = Processing.getInstanceById(getProcessingSketchID()); | ||
| 8 | 8 | if ( sketch == undefined ) | |
| 9 | 9 | setTimeout(tryFindSketch, 200); // retry in 0.2 secs | |
| 10 | 10 | else | |
@@ -20,11 +20,20 @@ function initVideos ( sketch ) { | |||
| 20 | 20 | ||
| 21 | 21 | video['loop'] = true; // as "loop" is not supported by many browsers | |
| 22 | 22 | ||
| 23 | + var lastTime = -1; | ||
| 24 | + var lastFrame = null; | ||
| 25 | + | ||
| 23 | 26 | // extending our HTMLVideoElement object to return a PImage | |
| 24 | 27 | video['getFrame'] = function () { | |
| 25 | - var img = new sketch.PImage; | ||
| 26 | - img.fromHTMLImageData(video); | ||
| 27 | - return img; | ||
| 28 | + if ( lastTime !== video.currentTime || !lastFrame ) | ||
| 29 | + { | ||
| 30 | + lastFrame = new sketch.PImage; | ||
| 31 | + lastFrame.fromHTMLImageData(video); | ||
| 32 | + lastTime = video.currentTime; | ||
| 33 | + return lastFrame; | ||
| 34 | + } else { | ||
| 35 | + return lastFrame; | ||
| 36 | + } | ||
| 28 | 37 | }; | |
| 29 | 38 | ||
| 30 | 39 | // similar to tryFindSketch this creates a loop that | |
@@ -40,13 +49,17 @@ function initVideos ( sketch ) { | |||
| 40 | 49 | tryAddVideo(); | |
| 41 | 50 | })( sketch, video ); | |
| 42 | 51 | ||
| 43 | - // force loop when set as this is currently not supported by most browsers | ||
| 44 | - addEvent(video,'ended',function(){ | ||
| 45 | - if ( 'loop' in this && this.loop ) { | ||
| 46 | - this.currentTime = 0; | ||
| 47 | - this.play(); | ||
| 48 | - } | ||
| 49 | - }); | ||
| 52 | + // this is a temporary fix for Chrome browsers sometimes not looping videos ... | ||
| 53 | + if ( window.navigator.appVersion.toLowerCase().indexOf('chrome') >= 0 ) { | ||
| 54 | + addEvent(video,'timeupdate',function(){ | ||
| 55 | + if ( video.currentTime == video.duration ) { | ||
| 56 | + video.src = video.currentSrc; | ||
| 57 | + } | ||
| 58 | + }); | ||
| 59 | + addEvent(video,'canplay',function(){ | ||
| 60 | + video.play(); | ||
| 61 | + }); | ||
| 62 | + } | ||
| 50 | 63 | } | |
| 51 | 64 | ||
| 52 | 65 | // http://html5demos.com/ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments