我正在尝试实现一个功能,当没有鼠标点击或鼠标移动时,程序会全屏播放视频,比如 x 秒。并在单击或移动鼠标时停止视频并返回上一个场景
目前我有这个工作..但是即使我点击并移动鼠标,视频也会在 5 秒后播放.. 我似乎无法找到关于如何关闭视频并继续前一个场景/fxml 的解决方案鼠标点击移动..
编写时的当前代码:
在鼠标空闲时播放视频:
PauseTransition delay = new PauseTransition(Duration.seconds(5));
delay.setOnFinished( event -> {
try {
Main.showVideo();
} catch (IOException ex) {
Logger.getLogger(UserMainPage2Controller.class.getName()).log(Level.SEVERE, null, ex);
}
} );
delay.play();
用于显示视频(位于我的主课内):
public static void showVideo() throws IOException
{
File f = new File("C:\\vid\\saitama.mp4");
Media media = new Media(f.toURI().toString());
MediaView mv = new MediaView();
MediaPlayer mp = new MediaPlayer(media);
mv.setMediaPlayer(mp);
FXMLLoader loader=new FXMLLoader();
loader.setLocation(Main.class.getResource("page/videoPlayer.fxml"));
mainLayout = loader.load();
StackPane root=new StackPane();
root.getChildren().add(mv);
stage.setScene(new Scene(root,1000,1000));
stage.setTitle("Video");
stage.setFullScreen(true);
stage.show();
mp.play();
}
而且我也不确定在我的 VideoPlayercontroller 类中放什么:现在它是空的。
public class VideoPlayerController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
所以我想做的只是在鼠标空闲时播放视频(没有点击或移动 x 秒).. 并在鼠标移动或点击时关闭视频.. 例如..
if mouseclicked then Main.showPreviousScene();