我可以在 javafx 中创建一个 GUI 并在 JavaFx 中调用 JMF 组件,就像这样
public class JMFComponent extends SwingComponent{
var panel: JPanel;
public var center: java.awt.Component on replace{
println("[center] set component: {center}");
panel.add(center, BorderLayout.CENTER);
}
public override function createJComponent():javax.swing.JComponent{
panel= new JPanel(new BorderLayout());
var size:Dimension = new Dimension(width, height);
panel.setPreferredSize(size);
panel.setMinimumSize(size);
panel.setMaximumSize(size);
panel.setSize(size);
return panel;
}
}
public class MyMedia extends CustomNode {
var xpos: Number;
var ypos: Number;
var dx: Number;
public var url: java.net.URL;
public var autoPlay: Boolean;
public override function create(): Node{
var comp:java.awt.Component;
var control:java.awt.Component;
var w:Number;
var h:Number;
var cw:Number;
var ch:Number;
var jmfCom:JMFComponent;
var player = Manager.createRealizedPlayer(url);
comp=player.getVisualComponent();
control=player.getControlPanelComponent();
if (autoPlay) {
player.start();
}
w=comp.getPreferredSize().getWidth();
h=comp.getPreferredSize().getHeight();
cw=control.getPreferredSize().getWidth();
ch=control.getPreferredSize().getHeight();
jmfCom=JMFComponent {
width:w
height:h+ch
center: comp
blocksMouse: true
bottom: control
};
return Group{
content: [
jmfCom
]
}
}
}
Stage {
title: "Media Example"
width: 500
height: 500
onClose: function(){ java.lang.System.exit(0);}
scene: Scene {
content: MyMedia{
url: (
new java.io.File("C://My//Videos//DELTA.MPG")).toURI().toURL()
autoPlay: true
}
}
}
视频可以在 JavaFx gui 中播放,但是当我将鼠标光标移动到 JMF 播放器的控制栏中时,视频窗口会同时移动。
有谁知道如何让 JMF 在 JavaFx 中正常工作?