Skip to content

Instantly share code, notes, and snippets.

@GoToLoop
Last active October 21, 2022 11:49
Show Gist options
  • Save GoToLoop/67023ba3e9ba1d0301c40f7c030d176a to your computer and use it in GitHub Desktop.
Save GoToLoop/67023ba3e9ba1d0301c40f7c030d176a to your computer and use it in GitHub Desktop.
Hacked Movie EoS Event
/**
* Hacked Movie EoS Event (v2.1.0)
* by GoToLoop (2022-Oct-20)
*
* Gist.GitHub.com/GoToLoop/67023ba3e9ba1d0301c40f7c030d176a
*
* Discourse.Processing.org/t/hacked-movie-eos-event-library/39375
* Forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item_1
*/
import processing.video.HackedMovie;
HackedMovie vid;
static final String FILENAME = "transit.mov";
void setup() {
frameRate(30);
textSize(050);
textAlign(CENTER, BASELINE);
fill(#FFFF00);
vid = new HackedMovie(this, FILENAME);
vid.play();
while (vid.width == 0 | vid.height == 0) delay(5);
surface.setSize(vid.width, vid.height);
}
void draw() {
if (!vid.ended) background(vid);
else {
background((color) random(#000000));
text("Playback has finished!", width >> 1, height >> 1);
}
}
void movieEvent(final HackedMovie m) {
m.read();
}
void eosEvent(final HackedMovie m) {
frameRate(1);
println(m);
}
/**
* Hacked Movie EoS Event (v2.1.0)
* by GoToLoop (2022-Oct-20)
*
* Gist.GitHub.com/GoToLoop/67023ba3e9ba1d0301c40f7c030d176a
*
* Discourse.Processing.org/t/hacked-movie-eos-event-library/39375
* Forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item_1
*/
package processing.video;
import processing.core.PApplet;
import java.lang.reflect.Method;
import org.freedesktop.gstreamer.GstObject;
import static org.freedesktop.gstreamer.Bus.EOS;
public class HackedMovie extends Movie {
public Method eosEventMethod;
public boolean ended;
public HackedMovie(final PApplet p, final String filename) {
super(p, filename);
addEOSListener(new MyEOS()).lookUpAndActivateEOSEventCallback();
}
public HackedMovie addEOSListener(final EOS eos) {
playbin.getBus().connect(eos);
return this;
}
public HackedMovie lookUpAndActivateEOSEventCallback() {
final Class<?> p = eventHandler.getClass();
try {
eosEventMethod = p.getMethod("eosEvent", Movie.class);
}
catch (final NoSuchMethodException e) {
}
try {
eosEventMethod = p.getMethod("eosEvent", HackedMovie.class);
}
catch (final NoSuchMethodException e) {
}
return this;
}
@Override public void setEventHandlerObject(final Object o) {
super.setEventHandlerObject(o);
final Class<?> p = o.getClass();
try {
movieEventMethod = p.getMethod("movieEvent", HackedMovie.class);
}
catch (final NoSuchMethodException e) {
}
}
@Override public void play() {
super.play();
ended = false;
}
class MyEOS implements EOS {
@Override public void endOfStream(final GstObject _) {
ended = true;
if (eosEventMethod != null) try {
eosEventMethod.invoke(eventHandler, HackedMovie.this);
}
catch (final ReflectiveOperationException e) {
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment