public class Controller {private boolean bind;@FXMLprivate AnchorPane root;//画板@FXMLprivate MediaView Myview;@FXMLprivate Slider jfxSlider;@FXMLprivate Slider soundss;@FXMLprivate ImageView play;@FXMLprivate ImageView sound;@FXMLprivate ImageView stop;@FXMLprivate Button switchhh;@FXMLprivate Button stt;@FXMLprivate Button quickplay;@FXMLprivate Button quickreturn;@FXMLvoid dragDrpped(DragEvent event){Dragboard dragboard =event.getDragboard();//创建拖拽对像if(dragboard.hasFiles()){File file =dragboard.getFiles().get(0);//读取拖拽的文件Media media =new Media(file.toURI().toString());MediaPlayer mediaPlayer = new MediaPlayer(media);//创建媒体对像并读取该文件//为多媒体播放对象设置事件mediaPlayer.setOnReady(()->{mediaPlayer.setAutoPlay(true);//文件拖拽进去时默认自动播放switchhh.setOnMouseClicked(event1 -> {mediaPlayer.pause();//当鼠标点击暂停键时视频暂停});stt.setOnMouseClicked(event1 -> {mediaPlayer.play();//当鼠标点击播放键时视频播放});soundss.setMax(1);//设置声音最大值为1//更改标尺文本soundss.setLabelFormatter(new StringConverter<Double>() {@Overridepublic String toString(Double object) {double dv= object;int v=(int)(object * 100);return Integer.toString(v);}@Overridepublic Double fromString(String string) {return null;}});soundss.valueProperty().bindBidirectional(mediaPlayer.volumeProperty());//将视频音量与音频标尺双向绑定Myview.setMediaPlayer(mediaPlayer);//对myview组件设置视频播放对象//视频进度条相关设置jfxSlider.setMin(mediaPlayer.getStartTime().toSeconds());//将视频进度条的最小值设为视频的开始时间的值jfxSlider.setMax(mediaPlayer.getTotalDuration().toSeconds());//将视频进度条的最大值设为视频的结束时间的值jfxSlider.setOnMousePressed(event1 -> bind =false);//设置鼠标点击事件,并利用bind关联下面鼠标释放事件jfxSlider.setOnMouseReleased(event1 -> {mediaPlayer.seek(Duration.seconds(jfxSlider.getValue()));//当鼠标释放时,读取视频在鼠标点击处的时刻的内容bind=true;});mediaPlayer.currentTimeProperty().addListener(new ChangeListener<Duration>() {@Overridepublic void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {if(bind)jfxSlider.setValue(newValue.toSeconds());//获取当前视频的时间进度}});//为快进按钮设置鼠标点击事件,若发生,则向后跳转十秒quickplay.setOnMouseClicked(event1 -> {mediaPlayer.seek(Duration.seconds(jfxSlider.getValue()+10));bind=true;});//为快退按钮设置鼠标点击事件,若发生,则向前跳转五秒quickreturn.setOnMouseClicked(event1 -> {mediaPlayer.seek(Duration.seconds(jfxSlider.getValue()-5));bind=true;});});}}@FXMLvoid dragOver(DragEvent event){event.acceptTransferModes(TransferMode.ANY);}}