在我的Swing应用程序中,我需要提供html的支持。因此,我在我的Swing应用程序中嵌入了一个JavaFX WebView。现在,在一些html页面上,我使用新的html5 -Tag播放视频。这在Windows和Linux上都能很好地工作。但在MacOS上,我只听到声音,看到一个黑色的视频帧和时间轨道在底部。
这是我从github获得的一个SSCCE。我刚刚将url更改为包含html5视频标记示例的url。如果您的MacOS用户可以尝试并告诉我在您的计算机上是否会发生同样的情况,那就太好了。当然,任何解决这一问题的想法都会受到赞赏。
SSCCE:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import com.sun.javafx.application.PlatformImpl;
/**
* SwingFXWebView
*/
public class JavaFXTest extends JPanel
{
private Stage stage;
private WebView browser;
private JFXPanel jfxPanel;
private JButton swingButton;
private WebEngine webEngine;
private Object geo;
public JavaFXTest()
{
this.initComponents();
}
public static void main(final String... args)
{
// Run this later:
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
final JFrame frame = new JFrame();
frame.getContentPane().add(new JavaFXTest());
frame.setMinimumSize(new Dimension(640, 480));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
private void initComponents()
{
this.jfxPanel = new JFXPanel();
this.createScene();
this.setLayout(new BorderLayout());
this.add(this.jfxPanel, BorderLayout.CENTER);
this.swingButton = new JButton();
this.swingButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(final ActionEvent e)
{
Platform.runLater(new Runnable()
{
@Override
public void run()
{
JavaFXTest.this.webEngine.reload();
}
});
}
});
this.swingButton.setText("Reload");
this.add(this.swingButton, BorderLayout.SOUTH);
}
/**
* createScene Note: Key is that Scene needs to be created and run on
* "FX user thread" NOT on the AWT-EventQueue Thread
*/
private void createScene()
{
PlatformImpl.startup(new Runnable()
{
@Override
public void run()
{
JavaFXTest.this.stage = new Stage();
JavaFXTest.this.stage.setTitle("Hello Java FX");
JavaFXTest.this.stage.setResizable(true);
final Group root = new Group();
final Scene scene = new Scene(root, 80, 20);
JavaFXTest.this.stage.setScene(scene);
// Set up the embedded browser:
JavaFXTest.this.browser = new WebView();
JavaFXTest.this.webEngine = JavaFXTest.this.browser.getEngine();
JavaFXTest.this.webEngine.load("http://camendesign.com/code/video_for_everybody/test.html");
final ObservableList<Node> children = root.getChildren();
children.add(JavaFXTest.this.browser);
JavaFXTest.this.jfxPanel.setScene(scene);
}
});
}
}发布于 2014-06-03 08:27:07
下面是一个半答案,这可能会有所帮助:甲骨文网站声明:“此时,在线安装和Java功能对于64位架构是不可用的。”
对我来说,这造成了很多问题,因为Java似乎是最新的,但实际上并非如此。在某些机器上,我可以通过手动更新Java 64位VM来解决实际问题。然而,在Mac上,视频仍然没有播放,只播放声音。
64位/32位问题变得更加严重,因为双击jar可能会在64位JVM中启动它,但是通过控制台在32位JVM中启动它。因此,如果在控制台中执行"java -version“,输出可能是"1.7.0 u45 32位”,但只要通过双击启动jar,它就会在过时的64位JVM中启动。
因此,如果您曾经在JavaFX问题中运行(特别是在UnsatisfiedLinkError中),并且您有一台64位计算机,那么只需安装最新的64位java,并希望它能够解决这个问题。
https://stackoverflow.com/questions/21459163
复制相似问题