-
Notifications
You must be signed in to change notification settings - Fork 0
/
Video.pde
101 lines (80 loc) · 2.19 KB
/
Video.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
import processing.video.*;
Movie initVideo(String dir) {
return new Movie(this, dir);
}
// Called every time a new frame is available to read
void movieEvent(Movie m) {
m.read();
}
// video application
class Video extends Window implements MenuListener, UIMenuSurfaceListener {
Movie aMovie;
float aMovieDur;
float aMovieTime;
boolean playing;
Video(String aM, PVector aPos, PVector aSize, UISceneElement aParent){
super(aPos, aSize, aParent);
// add buttons to the bottom bar
addControlButton(new ReleasableButton(0, "Play/Pause", ""));
addControlButton(new ReleasableButton(1, "Exit", ""));
// add menus
MenuSurface ms = new MenuSurface("Hello", 0);
ms.addButtonChild(new ReleasableButton(0, "Play/Pause", ""));
ms.addButtonChild(new ReleasableButton(1, "Exit", ""));
ms.setListener(this);
Menu m = new Menu("Options", 0);
m.addMenuSurface(ms);
m.addListener(this);
m.addHoldable(0, "Video");
m.addReleasable(0, "Exit");
addMenu(m);
aMovie = initVideo(aM);
aMovieTime = aMovie.time();
aMovie.loop();
playing = true;
}
/* from Window, behavious of assigned relesable buttons */
void onOver(int ID){}
void onRelease(int ID){
if (ID == 1) {
_Parent.killChild(this);
return;
}
if (playing){
aMovie.pause();
playing = false;
} else {
aMovie.play();
playing = true;
}
}
void onClick(int ID) {}
void renderElement() {
super.renderElement();
PVector p = getCurrentPos();
PVector s = getCurrentSize();
image(aMovie, (int)p.x, (int)p.y, (int)s.x, (int)s.y);
}
// from MenuListener
void onRelease(int menuId, int commandID){
if (menuId == 0 && commandID == 0){
_Parent.killChild(this);
}
}
void onHold(int menuId, int commandID){
}
// from surface listener
void onChoice(int surfaceID, int elementID){
if (surfaceID == 0 && elementID == 0){
if (playing){
aMovie.pause();
playing = false;
} else {
aMovie.play();
playing = true;
}
} else if (surfaceID == 0 && elementID == 1){
_Parent.killChild(this);
}
}
}