Skip to content

Commit 861d517

Browse files
committed
video fixes
1 parent b46d77b commit 861d517

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

sources/net.sf.j2s.java.core/src/swingjs/api/js/HTML5Video.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public static Object[] addActionListener(HTML5Video jsvideo, ActionListener list
231231
public Void apply(Object jsevent) {
232232
String name = (/** @j2sNative jsevent.type || */
233233
"?");
234+
System.out.println("HTML5Video " + name);
234235
ActionEvent e = new ActionEvent(new Object[] { jsvideo, jsevent }, 12345, name,
235236
System.currentTimeMillis(), 0);
236237
listener.actionPerformed(e);
@@ -258,7 +259,6 @@ public Void apply(Object jsevent) {
258259
* @param listeners an array of event/listener pairs created by
259260
* addActionListener
260261
*/
261-
@SuppressWarnings("unused")
262262
public static void removeActionListener(HTML5Video jsvideo, Object[] listeners) {
263263
if (listeners == null) {
264264
for (int i = 0; i < eventTypes.length; i++) {
@@ -314,7 +314,7 @@ public static JLabel createLabel(Object source) {
314314
* @param maxWidth
315315
* @return
316316
*/
317-
public static JDialog createDialog(Frame parent, Object source, int maxWidth, Runnable whenReady) {
317+
public static JDialog createDialog(Frame parent, Object source, int maxWidth, Function<HTML5Video, Void> whenReady) {
318318
JDialog dialog = new JDialog(parent);
319319
Container p = dialog.getContentPane();
320320
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
@@ -347,7 +347,7 @@ public void actionPerformed(ActionEvent e) {
347347
dialog.pack();
348348
// dialog.setVisible(false);
349349
if (whenReady != null)
350-
whenReady.run();
350+
whenReady.apply(jsvideo);
351351
}
352352

353353
}, "canplaythrough");
@@ -427,6 +427,10 @@ public static boolean nextFrame(HTML5Video jsvideo, double dt) {
427427
return canSeek.booleanValue();
428428
}
429429

430+
public static int getFrameCount(HTML5Video jsvideo) {
431+
return (int) (getDuration(jsvideo) / 0.033334);
432+
}
433+
430434
// HTMLMediaElement properties
431435

432436
// audioTracks

sources/net.sf.j2s.java.core/src/test/Test_Video.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.nio.file.Files;
1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import java.util.function.Function;
2122

2223
import javax.swing.BoxLayout;
2324
import javax.swing.ImageIcon;
@@ -33,7 +34,6 @@
3334
import javax.swing.WindowConstants;
3435

3536
import swingjs.api.JSUtilI;
36-
import swingjs.api.js.DOMNode;
3737
import swingjs.api.js.HTML5Video;
3838

3939
/**
@@ -105,11 +105,12 @@ public Test_Video() {
105105

106106
// A little trick to allow "final" self reference in a Runnable parameter
107107
JDialog[] dialog = new JDialog[1];
108-
dialog[0] = HTML5Video.createDialog(null, label, 500, new Runnable() {
108+
dialog[0] = HTML5Video.createDialog(null, label, 500, new Function<HTML5Video, Void>() {
109109

110110
@Override
111-
public void run() {
111+
public Void apply(HTML5Video video) {
112112
dialog[0].setVisible(true);
113+
return null;
113114
}
114115

115116
});

0 commit comments

Comments
 (0)