[英]javafx mediaview only the audio is playing
Im trying to embed a video in a website to a mediaview of a simple javafx application. 我试图将视频嵌入网站中,以访问简单javafx应用程序的mediaview。 Ive got a sample code which I used as my javafx code.
我有一个示例代码,用作我的javafx代码。 It opens the scene and plays the audio but wont play the video.
它会打开场景并播放音频,但不会播放视频。 How can I make it play the audio?
如何播放音频? Im using netbeans IDE 8.0.2,JavaFx 8 and scene builder 2.0 The Code ive tried is below.
我正在使用netbeans IDE 8.0.2,JavaFx 8和场景构建器2.0。 Thanx in advanced.
感谢高级。
@FXML MediaView mdv;
Media media;
public static MediaPlayer mpl;
@Override
public void initialize(URL url, ResourceBundle rb) {
media=new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv");
mpl=new MediaPlayer(media);
mpl.setAutoPlay(true);
mdv=new MediaView(mpl);
mpl.play();
mpl.setOnError(new Runnable() {
@Override public void run() {
System.out.println("Current Error: " + mpl.getError());
}
});
}
This is how I load the children to the stage 这就是我把孩子们装到舞台上的方式
public class Production extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Vdo.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
the FXML Ive got after creating the GUI from scene builder is below 下面是从场景构建器创建GUI后获得的FXML Ive
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.media.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="production.VdoController">
<children>
<MediaView fx:id="mdv" fitHeight="300.0" fitWidth="300.0" layoutX="125.0" layoutY="85.0" />
<Button layoutX="235.0" layoutY="51.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>
You are re-initializing the MediaView that has been initialized by the FXMLoader
. 您正在重新初始化由FXMLoader初始化的
FXMLoader
。 Never do this, because you will loose the reference to the original node. 永远不要这样做,因为您将丢失对原始节点的引用。
You should just set the MediaPlayer to the MediaView instead of re-initializing it by using the setMediaPlayer() . 您应该只将MediaPlayer设置为MediaView,而不是通过使用setMediaPlayer()对其进行初始化。
@Override
public void initialize(URL url, ResourceBundle rb) {
media=new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv");
mpl=new MediaPlayer(media);
mpl.setAutoPlay(true);
mdv.setMediaPlayer(mpl);
mpl.play();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.