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

Permit implementing movieEvent without having to link to Movie at bui… · bgc/processing@d6f34e5 · GitHub

Repository navigation

Commit d6f34e5

Browse files
Jonathan Feinberg
committed
Permit implementing movieEvent without having to link to Movie at buildtime.
This is useful for Python mode, or any other Java-compatible Processing that doesn't allow reflection on the sketch.
1 parent ab06f40 commit d6f34e5

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

  • java/libraries/video/src/processing/video

‎java/libraries/video/src/processing/video/Movie.java‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,19 @@ protected void setEventHandlerObject(Object obj) {
722722
eventHandler = obj;
723723

724724
try {
725-
movieEventMethod = eventHandler.getClass().getMethod("movieEvent",
726-
new Class[] { Movie.class });
725+
movieEventMethod = eventHandler.getClass().getMethod("movieEvent", Movie.class);
726+
return;
727+
} catch (Exception e) {
728+
// no such method, or an error... which is fine, just ignore
729+
}
730+
731+
// movieEvent can alternatively be defined as receiving an Object, to allow
732+
// Processing mode implementors to support the video library without linking
733+
// to it at build-time.
734+
try {
735+
movieEventMethod = eventHandler.getClass().getMethod("movieEvent", Object.class);
727736
} catch (Exception e) {
728-
// no such method, or an error.. which is fine, just ignore
737+
// no such method, or an error... which is fine, just ignore
729738
}
730739
}
731740

@@ -808,20 +817,10 @@ protected synchronized void invokeEvent(int w, int h, IntBuffer buffer) {
808817
}
809818

810819
if (playing) {
811-
// Creates a movieEvent.
812-
if (movieEventMethod != null) {
813-
try {
814-
movieEventMethod.invoke(eventHandler, new Object[] { this });
815-
} catch (Exception e) {
816-
System.err.println("error, disabling movieEvent() for " + filename);
817-
e.printStackTrace();
818-
movieEventMethod = null;
819-
}
820-
}
820+
fireMovieEvent();
821821
}
822822
}
823823

824-
825824
protected synchronized void invokeEvent(int w, int h, Buffer buffer) {
826825
available = true;
827826
bufWidth = w;
@@ -835,19 +834,22 @@ protected synchronized void invokeEvent(int w, int h, Buffer buffer) {
835834
natBuffer = buffer;
836835

837836
if (playing) {
838-
// Creates a movieEvent.
839-
if (movieEventMethod != null) {
840-
try {
841-
movieEventMethod.invoke(eventHandler, new Object[] { this });
842-
} catch (Exception e) {
843-
System.err.println("error, disabling movieEvent() for " + filename);
844-
e.printStackTrace();
845-
movieEventMethod = null;
846-
}
847-
}
837+
fireMovieEvent();
848838
}
849839
}
850840

841+
private void fireMovieEvent() {
842+
// Creates a movieEvent.
843+
if (movieEventMethod != null) {
844+
try {
845+
movieEventMethod.invoke(eventHandler, this);
846+
} catch (Exception e) {
847+
System.err.println("error, disabling movieEvent() for " + filename);
848+
e.printStackTrace();
849+
movieEventMethod = null;
850+
}
851+
}
852+
}
851853

852854
protected void eosEvent() {
853855
if (repeat) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL