FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Processing.js 1.4.0 and updates to js examples and todo · studioijeoma/processing@c79c3f1 · GitHub

Repository navigation

Commit c79c3f1

Browse files
committed
Processing.js 1.4.0 and updates to js examples and todo
1 parent 28128aa commit c79c3f1

6 files changed

Lines changed: 635 additions & 401 deletions

File tree

‎javascript/examples/HTML5/Video/atTheStation/atTheStation.pde‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
void setVideo ( Video v )
7777
{
7878
video = v;
79+
console.log( v );
7980
}
8081

8182
/* make Processing understand the HTMLVideoElement */

‎javascript/examples/HTML5/Video/atTheStation/mov.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ window.onload = function () {
33
video['loop'] = true;
44

55
function tryFindSketch () {
6-
var sketch = Processing.instances[0];
6+
var sketch = Processing.getInstanceById(getProcessingSketchID());
77
if ( sketch == undefined )
88
return setTimeout(tryFindSketch, 200); // retry in 0.2 secs
99

@@ -16,7 +16,7 @@ window.onload = function () {
1616

1717
(function( s, v ){
1818
var tryAddVideo = function () {
19-
if ( v.readyState > 0 ) {
19+
if ( v.readyState > 2 ) {
2020
s.setVideo(v);
2121
} else {
2222
setTimeout(tryAddVideo, 200);

‎javascript/examples/HTML5/Video/charmyDance/charmyDance.pde‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* @pjs transparent=true; */
2-
31
/**
42
* <p>This example shows you how to use video with a transparency
53
* which currently is not natively supported by web video formats (H264 / OGV).</p>
@@ -44,7 +42,13 @@
4442
PImage frame = video.getFrame();
4543
PImage rgbImage = frame.get(frame.width/2,0,frame.width/2,frame.height);
4644
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();
4852
image( rgbImage, width/2-rgbImage.width/2, 0 );
4953
}
5054
}

‎javascript/examples/HTML5/Video/charmyDance/mov.js‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ window.onload = function () {
44

55
// try to find the Processing sketch instance, or retry
66
function tryFindSketch () {
7-
var sketch = Processing.instances[0];
7+
var sketch = Processing.getInstanceById(getProcessingSketchID());
88
if ( sketch == undefined )
99
setTimeout(tryFindSketch, 200); // retry in 0.2 secs
1010
else
@@ -20,11 +20,20 @@ function initVideos ( sketch ) {
2020

2121
video['loop'] = true; // as "loop" is not supported by many browsers
2222

23+
var lastTime = -1;
24+
var lastFrame = null;
25+
2326
// extending our HTMLVideoElement object to return a PImage
2427
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+
}
2837
};
2938

3039
// similar to tryFindSketch this creates a loop that
@@ -40,13 +49,17 @@ function initVideos ( sketch ) {
4049
tryAddVideo();
4150
})( sketch, video );
4251

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+
}
5063
}
5164

5265
// http://html5demos.com/

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL