bet 11/11 Sana 18.07.2022 Hajmi 4,45 Mb. #822180
Bog'liq
Saidov Og\'abek
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
public Slider AudioSlider ;
public Button btn_pause ;
public Button btn_play ;
public Slider AudioSider =new Slider();
public Slider slider = new Slider();
public Button chooseButton ;
public Button btn_Stop ;
public String audioFile = null ;
private MediaPlayer player ;
Boolean fileinuse = false ;
Label musicLabel = new Label("Fayl hoziricha mavjud emas" );
public void chooseFile() throws MalformedURLException {
FileChooser chooser = new FileChooser();
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("o'zingizning(*.mp3) faylingizni tanlang" , "*.mp3" );
chooser.getExtensionFilters().add(filter);
File file = chooser.showOpenDialog(null );
if ( file !=null ){
musicLabel .setText(file.getPath());
this .audioFile = file.toURI().toURL().toString();
}else {
musicLabel .setText("Noto'g'ri Fayl kiritildi" );
this .audioFile = null ;
}
slider .setValue(slider .getMax()/2);
fileinuse = false ;
// player.stop();
player .play();
}
public void playFile(){
if (fileinuse ){
player .play();
}else {
Media pick = new Media(this .audioFile );
player = new MediaPlayer(pick);
player .play();
}
// slider.setValue(player.getVolume()*100);
fileinuse = true ;
AudioSlider .valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Number> observable, Number oldValue, Number newValue) {
player .seek(Duration.seconds (newValue.doubleValue()));
}
});
}
public void pauseFile(){
player .pause();
}
public void stopFile(){
player .stop();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
slider .valueProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
player .setVolume(slider .getValue() / 100);
} });
/*
try {
chooseFile();
AudioSlider.maxProperty().bind(Bindings.createDoubleBinding(
() -> player.getTotalDuration().toSeconds(),
player.totalDurationProperty()));
AudioSlider.setOnMouseClicked((MouseEvent event) -> {
player.seek(Duration.seconds(AudioSlider.getValue()));
});
player.currentTimeProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Duration> observable, Duration oldValue, Duration newValue) {
AudioSider.setValue(newValue.toSeconds()*10);
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
*/
}
private void AudioSlide(){
}
private void AudioSeek(){
}
public void volum(InputMethodEvent inputMethodEvent) {
}
}
Stillar
.root
{
-fx-background-image:url('../Images/bb.jpg' );
}
.slider .track {
-fx-background-color:white;
-fx-background-insets:2;
}
.slider .thumb {
-fx-background-color:#2196f3;
}
FXML
xml version= "1.0" encoding= "UTF-8" ?>
import javafx.scene.image.* ?>
import java.net.* ?>
import java.lang.* ?>
import javafx.geometry.* ?>
import javafx.scene.control.* ?>
import javafx.scene.effect.* ?>
import javafx.scene.layout.* ?>
import javafx.scene.text.* ?>
import javafx.geometry.Insets ?>
import javafx.scene.control.Slider ?>
import javafx.scene.effect.DropShadow ?>
import javafx.scene.layout.AnchorPane ?>
import javafx.scene.layout.ColumnConstraints ?>
import javafx.scene.layout.GridPane ?>
import javafx.scene.layout.HBox ?>
import javafx.scene.layout.RowConstraints ?>
import javafx.scene.layout.VBox ?>
import javafx.scene.text.Text ?>
<GridPane alignment= "center" hgap= "10" vgap= "10" xmlns= "http://javafx.com/javafx/8" xmlns: fx = "http://javafx.com/fxml/1" fx :controller= "sample.Controller" >
<columnConstraints >
<ColumnConstraints />
columnConstraints >
<rowConstraints >
<RowConstraints />
rowConstraints >
<children >
<AnchorPane prefHeight= "525.0" prefWidth= "732.0" style= "-fx-background-color: transparent;" >
<padding >
<Insets bottom= "10.0" left= "10.0" right= "10.0" top= "10.0" />
padding >
<children >
<HBox layoutX= "56.0" layoutY= "55.0" AnchorPane.bottomAnchor= "0.0" AnchorPane.leftAnchor= "0.0" AnchorPane.rightAnchor= "0.0" AnchorPane.topAnchor= "0.0" >
<children >
<VBox alignment= "TOP_RIGHT" prefHeight= "200.0" prefWidth= "100.0" styleClass= "left" stylesheets= "@Style/ss.css" HBox.hgrow= "ALWAYS" >
<children >
<Text strokeType= "OUTSIDE" strokeWidth= "0.0" style= "-fx-font-size: 3em; -fx-font-weight: bold; -fx-font-family: Quicksand; -fx-fill: white;" text= "Music For TATU" >
<effect >
<DropShadow />
effect >
Text >
<VBox alignment= "BOTTOM_RIGHT" styleClass= "root" stylesheets= "@Style/ss.css" VBox.vgrow= "SOMETIMES" >
<children >
<Text strokeType= "OUTSIDE" strokeWidth= "0.0" style= "-fx-font-family: Quicksand; -fx-font-weight: bold; -fx-font-size: 2.2em; -fx-fill: white;" text= "Music Player By" >
<effect >
<DropShadow />
effect >
Text >
<Text strokeType= "OUTSIDE" strokeWidth= "0.0" style= "-fx-font-family: Quicksand; -fx-font-weight: bold; -fx-font-size: 2.2em; -fx-fill: white;" text= "Husan C0d3r" >
<effect >
<DropShadow />
effect >
Text >
children >
<padding >
<Insets bottom= "20.0" left= "20.0" right= "20.0" top= "20.0" />
padding >
<VBox.margin >
<Insets />
VBox.margin >
VBox >
children >
VBox >
<VBox alignment= "TOP_CENTER" prefHeight= "200.0" prefWidth= "100.0" HBox.hgrow= "ALWAYS" >
<children >
<Text strokeType= "OUTSIDE" strokeWidth= "0.0" style= "-fx-font-size: 2em; -fx-font-family: Quicksand; -fx-font-weight: bold; -fx-fill: #4b4b4b;" text= "Never Give Up" textAlignment= "CENTER" wrappingWidth= "195.13671875" />
<Text strokeType= "OUTSIDE" strokeWidth= "0.0" style= "-fx-font-size: 2em; -fx-font-family: Quicksand; -fx-font-weight: bold; -fx-fill: #4b4b4b;" text= "Justin Beiber" textAlignment= "CENTER" wrappingWidth= "200.13671875" />
<VBox alignment= "TOP_CENTER" nodeOrientation= "LEFT_TO_RIGHT" prefHeight= "436.0" prefWidth= "298.0" style= "-fx-background-color: #e2e2e2;" stylesheets= "@Style/ss.css" VBox.vgrow= "ALWAYS" >
<children >
<Slider fx :id= "AudioSlider" />
<HBox >
<padding >
<Insets bottom= "5.0" left= "5.0" right= "5.0" top= "5.0" />
padding >
<children >
<HBox alignment= "CENTER_RIGHT" HBox.hgrow= "ALWAYS" >
<children >
<ImageView fitHeight= "23.0" fitWidth= "45.0" pickOnBounds= "true" preserveRatio= "true" HBox.hgrow= "NEVER" >
<HBox.margin >
<Insets bottom= "10.0" left= "10.0" right= "10.0" top= "-3.0" />
HBox.margin >
<image >
<Image url= "@Images/icons8-speaker-64.png" />
image >
ImageView >
children >HBox >
<Slider fx :id= "slider" onInputMethodTextChanged= "#volum" prefHeight= "14.0" prefWidth= "123.0" />
children >
HBox >
<Button fx :id= "btn_pause" mnemonicParsing= "false" onAction= "#pauseFile" prefHeight= "25.0" prefWidth= "58.0" text= "Pause" />
<Button fx :id= "btn_play" mnemonicParsing= "false" onAction= "#playFile" prefHeight= "25.0" prefWidth= "57.0" text= "Play" />
<Button fx :id= "chooseButton" mnemonicParsing= "false" onAction= "#chooseFile" text= "Choose" />
<Button fx :id= "btn_Stop" mnemonicParsing= "false" onAction= "#stopFile" prefHeight= "25.0" prefWidth= "54.0" text= "Stop" />
children >
<padding >
<Insets bottom= "10.0" left= "10.0" right= "10.0" top= "10.0" />
padding >
<VBox.margin >
<Insets />
VBox.margin >
VBox >
children >
<padding >
<Insets bottom= "10.0" left= "10.0" right= "10.0" top= "10.0" />
padding >
VBox >
children >
HBox >
children >
AnchorPane >
children >
GridPane >
Do'stlaringiz bilan baham: