我正在尝试使用java,javaFX和scenebulider模仿电视屏幕。目前,我可以播放视频,但是我不知道如何首先将其关闭,然后在按下按钮后将其播放。 这是我的控制器代码
public class Controller implements Initializable {
@FXML
private Slider suwak2;
@FXML
private Slider suwak5;
@FXML
private Slider suwak1;
@FXML
private Slider suwak4;
@FXML
private Slider suwak6;
@FXML
private Slider suwak3;
@FXML
private ToggleButton wlacznik;
@FXML
private MediaView mv;
private MediaPlayer mp;
private Media me;
@Override
public void initialize(URL location, ResourceBundle resources)
{
String path=new File("src/application/lol.mp4").getAbsolutePath();
Path clip = new Path(new MoveTo(50, 400), new ArcTo(50, 200, 0, 50, 0, false, true), new HLineTo(450), new ArcTo(50, 200, 0, 350, 400, false, true), new ClosePath());
clip.setFill(Color.BLACK);
clip.setStroke(null);
mv.setClip(clip);
me = new Media(new File(path).toURI().toString());
mp = new MediaPlayer(me);
mv.setMediaPlayer(mp);
mp.setAutoPlay(true);
mp.setCycleCount(MediaPlayer.INDEFINITE);
suwak1.setValue(mp.getVolume() * 100);
suwak1.valueProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
mp.setVolume(suwak1.getValue()/100);
}
});
}
}
suwak1是我的音量滑块,wlacznik是我的切换按钮,可以打开和关闭它。
答案 0 :(得分:0)
也许您需要Button
才能播放/停止
Button stop = new Button("STOP");
stop.setOnAction((e) -> mp.stop());
Button play = new Button("Play");
play.setOnAction((e) -> mp.play());