gpt4 book ai didi

java - JavaFX 中的媒体播放器

转载 作者:行者123 更新时间:2023-12-01 12:27:39 28 4
gpt4 key购买 nike

我担心自本教程发布以来 JavaFX 已经经历了一些修改:http://www.youtube.com/watch?v=bWl98dhvf8Q

请给我一些提示,告诉我应该在此代码中更改哪些内容,或者这种代码是否有效?谢谢。

代码如下:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.Group;


public class BiPlayer extends Application {

public static void main(String[] args){

launch(args);

}

@Override
public void start(Stage primaryStage) throws Exception {
Group videoPane = new Group();

Media media = new Media("C:\\Users\\Insanovation\\Downloads\\P.mp4");
MediaPlayer player = new MediaPlayer(media);
MediaView view = new MediaView(player);

videoPane.getChildren().add(view);
Scene scene = new Scene (videoPane, 400, 400, Color.BLACK);
primaryStage.setScene(scene);
primaryStage.show();

player.play();
}
}

这是输出:

    Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$48/1394438858.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Insanovation\Downloads\F.mp3
at javafx.scene.media.Media.<init>(Media.java:383)
at biplayer.BiPLAYER.start(BiPLAYER.java:24)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/270894642.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$44/1147985808.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1822121612.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1267032364.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/636718812.run(Unknown Source)
... 1 more
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Insanovation\Downloads\F.mp3
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parse(URI.java:3058)
at java.net.URI.<init>(URI.java:588)
at javafx.scene.media.Media.<init>(Media.java:381)
... 15 more
Exception running application biplayer.BiPLAYER
Java Result: 1

最佳答案

查看您复制并粘贴的异常,很明显抛出的异常是 URISyntaxException。然后它列出了有问题的字符,该字符位于索引 2(反斜杠字符)处。

如果您查看 URI 的文档 herehere ,您将看到 URI 中只接受正斜杠。如果您将路径中的反斜杠更改为正斜杠,如下所示:

file:C:/Users/Insanovation/Downloads/F.mp4

我相信它应该有效。

关于java - JavaFX 中的媒体播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26196809/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com