我无法使JavaFX媒体播放器正常工作。我正进入(状态 一条错误消息,提示java.lang.reflect.InvocationTargetException。我研究了 此错误消息,并找到一条帖子,说我正在调用2个不同的类 同名。但是我找不到它们是什么类。
有人对此有任何经验吗?我认为该消息仅与JavaFx API一起使用。这是代码:
import java.io.File;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Broadcaster extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage) {
String workingDir = System.getProperty("C:/Users/Tito/Desktop");
final File f = new File(workingDir, "Jeremy.wmv");
final Media m = new Media(f.toURI().toString());
final MediaPlayer mp = new MediaPlayer(m);
final MediaView mv = new MediaView(mp);
final DoubleProperty width = mv.fitWidthProperty();
final DoubleProperty height = mv.fitHeightProperty();
width.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
height.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));
mv.setPreserveRatio(true);
StackPane root = new StackPane();
root.getChildren().add(mv);
final Scene scene = new Scene(root, 960, 540);
scene.setFill(Color.BLACK);
primaryStage.setScene(scene);
primaryStage.setTitle("Full Screen Video Player");
primaryStage.setFullScreen(true);
primaryStage.show();
mp.play();
}
}
// This code was found on
http://www.java2s.com/Code/Java/JavaFX/FullScreenVideoPlayer.htm
答案 0 :(得分:0)
问题是我的文件位置。由于某种原因,代码没有寻找 字符串workingDir = System.getProperty(“ C:/ Users / Tito / Desktop”)中的文件; 在C:\ Users \ Tito \ eclipse-workspace \ Broadcast中寻找它。我必须找出 为什么。当我将媒体文件移动到C:\ Users \ Tito \ eclipse-workspace \ Broadcast时,它播放了 音频,而不是视频。