MainController.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | package application; import java.io.File; import java.net.URL; import java.util.ResourceBundle; import javafx.beans.binding.Bindings; import javafx.beans.property.DoubleProperty; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; public class MainController implements Initializable{ @FXML private MediaView mv; MediaPlayer mp; Media me; @Override public void initialize(URL location, ResourceBundle resources) { String path = new File("Adding Play, Pause, Start, Fast, Slow Buttons to Media Player/media/Test.mp4").getAbsolutePath(); me = new Media(new File(path).toURI().toString()); mp = new MediaPlayer(me); mv.setMediaPlayer(mp); //mp.setAutoPlay(true); DoubleProperty width = mv.fitWidthProperty(); DoubleProperty height = mv.fitHeightProperty(); width.bind(Bindings.selectDouble(mv.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mv.sceneProperty(), "height")); } //시작 public void play(ActionEvent event) { mp.play(); mp.setRate(1); } //정지 public void pause(ActionEvent event) { mp.pause(); } public void fast(ActionEvent event) { //mp.setRate(1);// 노멀 스피드 mp.setRate(2);// 2배 스피드 //mp.setRate(0.5);// 0.5배 스피드 } public void slow(ActionEvent event) { mp.setRate(.5); } public void reload(ActionEvent event) { mp.seek(mp.getStartTime()); mp.play(); } public void start(ActionEvent event) { mp.seek(mp.getStartTime()); mp.stop(); } public void last(ActionEvent event) { mp.seek(mp.getTotalDuration()); mp.stop(); } } | cs |
'Java > JavaFx' 카테고리의 다른 글
JavaFX 33. Adding Volume Slider to Media Player (0) | 2016.08.29 |
---|---|
JavaFX 31. Media Player in JavaFX (0) | 2016.08.29 |
JavaFX 30. Event Handler for a Line Chart (0) | 2016.08.29 |
JavaFX 29. Multiple Line Chart (0) | 2016.08.29 |
JavaFX 28. Line Chart (0) | 2016.08.29 |