Guest User

Untitled

a guest
Oct 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. import java.io.File;
  2. import java.net.URL;
  3.  
  4. import javafx.util.Duration;
  5. import java.util.ResourceBundle;
  6.  
  7. import javafx.beans.value.ChangeListener;
  8. import javafx.beans.value.ObservableValue;
  9.  
  10. import javafx.event.ActionEvent;
  11. import javafx.event.EventHandler;
  12. import javafx.scene.input.MouseEvent;
  13.  
  14. import javafx.fxml.FXML;
  15. import javafx.fxml.Initializable;
  16.  
  17. import javafx.scene.control.Label;
  18. import javafx.scene.control.Slider;
  19. import javafx.scene.media.Media;
  20. import javafx.scene.media.MediaPlayer;
  21. import javafx.scene.media.MediaView;
  22. public class VideoController implements Initializable {
  23.  
  24. private MediaPlayer mediaPlayer;
  25.  
  26. @FXML
  27. private Label label;
  28.  
  29. @FXML
  30. private Slider seekSlider;
  31.  
  32. @FXML
  33. private MediaView mediaView;
  34. private Media media;
  35.  
  36. private String filepath;
  37.  
  38. @FXML
  39. private void pauseVideo(ActionEvent event){
  40. mediaPlayer.pause();
  41. }
  42.  
  43. @FXML
  44. private void playVideo(ActionEvent event){
  45. mediaPlayer.play();
  46. mediaPlayer.setRate(1);
  47. }
  48.  
  49. @FXML
  50. private void stopVideo(ActionEvent event){
  51. mediaPlayer.stop();
  52. }
  53.  
  54. @Override
  55. public void initialize(URL url, ResourceBundle rb) {
  56. String path = new File("src/Videos/Video Proyecto.mp4").getAbsolutePath();
  57. media = new Media(new File(path).toURI().toString());
  58. mediaPlayer = new MediaPlayer(media);
  59. mediaView.setMediaPlayer(mediaPlayer);
  60. mediaPlayer.setAutoPlay(false);
  61. mediaPlayer.currentTimeProperty().addListener(new ChangeListener<Duration>() {
  62. @Override
  63. public void changed(ObservableValue<? extends Duration> observableValue, Duration duration, Duration current) {
  64. seekSlider.setMin(0.0);
  65. seekSlider.setValue(0.0);
  66. seekSlider.setMax(mediaPlayer.getTotalDuration().toSeconds());
  67.  
  68. seekSlider.setValue(current.toSeconds());
  69. }
  70. });
  71.  
  72. seekSlider.setOnMouseClicked(new EventHandler<MouseEvent>(){
  73. @Override
  74. public void handle(MouseEvent event) {
  75. mediaPlayer.seek(Duration.seconds(seekSlider.getValue()));
  76. }
  77. });
  78. }
  79.  
  80. }
  81.  
  82. import javafx.application.Application;
  83. import javafx.fxml.FXML;
  84. import javafx.fxml.FXMLLoader;
  85. import javafx.scene.Parent;
  86. import javafx.scene.Scene;
  87. import javafx.stage.Stage;
  88. import javafx.stage.StageStyle;
  89.  
  90.  
  91. public class Estanquet extends Application {
  92.  
  93. @Override
  94. public void start(Stage stage) throws Exception {
  95. Parent root = FXMLLoader.load(getClass().getResource("Index.fxml"));
  96.  
  97. Scene scene = new Scene(root);
  98. stage.initStyle(StageStyle.UNDECORATED);
  99. stage.setFullScreen(true);
  100. stage.setScene(scene);
  101. stage.show();
  102. }
  103.  
  104. /**
  105. * @param args the command line arguments
  106. */
  107. public static void main(String[] args) {
  108. launch(args);
  109. }
  110.  
  111. }
  112.  
  113. import java.io.IOException;
  114. import java.net.URL;
  115. import java.util.ResourceBundle;
  116. import javafx.event.ActionEvent;
  117. import javafx.fxml.FXML;
  118. import javafx.fxml.FXMLLoader;
  119. import javafx.fxml.Initializable;
  120. import javafx.scene.Node;
  121. import javafx.scene.Parent;
  122. import javafx.scene.Scene;
  123. import javafx.scene.layout.BorderPane;
  124. import javafx.stage.Stage;
  125.  
  126. public class IndexController implements Initializable {
  127.  
  128. @FXML
  129. private void changeScreenButtonPushed(ActionEvent event) {
  130. Parent videoP = FXMLLoader.load(getClass().getResource("Video.fxml"));
  131. Scene videoS = new Scene(videoP);
  132.  
  133. Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
  134. window.setScene(videoS);
  135. window.show();
  136. }
  137.  
  138.  
  139.  
  140. @FXML
  141. public void changeScreenButtonPushed2(ActionEvent event) throws IOException{
  142. Parent imagesP = FXMLLoader.load(getClass().getResource("Images.fxml"));
  143. Scene videoS = new Scene(videoP);
  144.  
  145. Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
  146. window.setScene(videoS);
  147. window.show();
  148. }
  149.  
  150.  
  151. @Override
  152. public void initialize(URL url, ResourceBundle rb) {
  153. // TODO
  154. }
  155.  
  156.  
  157. }
Add Comment
Please, Sign In to add comment