-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVideoController.pde
125 lines (106 loc) · 2.58 KB
/
VideoController.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Video
* Video Controller
*
* (c) Tim Greiser - 2015
* Released under the terms of MIT License
*/
import processing.video.*;
import java.util.Map;
class VideoController extends Controller {
boolean active = false;
Movie movie;
ScrollableList d1;
boolean playing;
void setup(PApplet _app, LEDMap _map) {
super.setup(_app, _map);
background(cb1);
int spacer = 10;
d1 = c5.addScrollableList("videos")
.setPosition(map.w+spacer, 15+spacer)
.setType(ControlP5.LIST)
.setColorBackground(cb3)
.setColorActive(cg1)
.setSize(230,205);
customize(d1, "Movies - Press 0-1");
initVideos();
movie = new Movie(app, "aeDomeDesign_1.mov");
movie.loop();
playing = true;
println("Video setup and playing");
}
void initVideos() {
File[] files = new File(sketchPath+"/data").listFiles();
int iX = 0;
for (int i=0;i<files.length;i++) {
String name = files[i].getName();
if (name.toLowerCase().endsWith(".mov") == false) { continue; }
println("Added " + name + " at " + str(iX));
d1.addItem(name, iX++);
}
}
Movie movie() {
return movie;
}
void stop() {
movie.dispose();
movie = null;
}
void playVideo(int sel) {
Map<String,Object> vi = d1.getItem(sel);
String filekey = "text";
String file = vi.get(filekey).toString();
println("Playing video : "+file);
this.stop();
movie = new Movie(app, file);
movie.loop();
}
void draw()
{
if (active == true) {
//println("Drawing movie frame");
//println(movie);
if (movie.available()) {
movie.read();
}
image(movie, 0, 0, map.w, map.h);
}
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom(d1)) {
videoController.playVideo(int(theEvent.getValue()));
}
}
void keyPressed() {
println(key);
if (key == 32) {
if (playing == true) {
movie.pause();
playing = false;
} else {
movie.play();
playing = true;
}
}
if (key >= 48 && key <= 57) {
String file = "";
try {
Map<String,Object> vi = d1.getItem(key-48);
file = vi.get("text").toString();
println("Loading " + file);
d1.setValue((float)key-48);
//movie = new Movie(app, file);
//movie.loop();
} catch (java.lang.IndexOutOfBoundsException e) {
// no need to complain
}
}
if (key == CODED) {
}
}
void movieEvent(Movie m) {
if (m != null) {
m.read();
}
}
}