JavaFX autre type d'audio
Bonjour pouvez vous m'aidé à ajouter un autre type d'audio (mp3,wav, .....)
dans cette section là je veux bien que vous m'aidiez à ajouter d'autre type d'audio :D
Code:
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("select a file (*.mp4)", "*.mp4");
Code:
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tp1;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.InvalidationListener;
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.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.FileChooser;
public class FXMLDocumentController implements Initializable {
@FXML
private MediaPlayer mediaPlayer ;
@FXML
private MediaView mediaView ;
private String filePatch;
@FXML
private Slider slider;
@FXML
private void handleButtonAction(ActionEvent event) {
// ajout d'un fichier audio de type mp4
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("select a file (*.mp4)", "*.mp4");
fileChooser.getExtensionFilters().add(filter);
File file = fileChooser.showOpenDialog(null);
filePatch = file.toURI().toString();
if(filePatch != null)
{
Media media = new Media (filePatch);
mediaPlayer = new MediaPlayer(media);
mediaView.setMediaPlayer(mediaPlayer);
//pour ajuster la video sur sur les boutons
DoubleProperty width = mediaView.fitWidthProperty();
DoubleProperty hight = mediaView.fitHeightProperty();
width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
hight.bind(Bindings.selectDouble(mediaView.sceneProperty(), "hight"));
mediaPlayer.play();
}
}
@FXML
private void pauseVideo(ActionEvent event) {
mediaPlayer.pause();
}
@FXML
private void playVideo(ActionEvent event) {
mediaPlayer.play();
mediaPlayer.setRate(1);
}
@FXML
private void stopVideo(ActionEvent event) {
mediaPlayer.stop();
}
@FXML
private void fasterVideo(ActionEvent event) {
mediaPlayer.setRate(2);
}
@FXML
private void slowerVideo(ActionEvent event) {
mediaPlayer.setRate(0.5);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
} |