In: Computer Science
JAVAFX
Create a JavaFx application that is an MP3 player. The size of the media player should be 800 pixels in width and 650 pixels in height. The media player should have a TextField that allows the user to type the full path of the .mp3 file to be played. The application should also use 2 Checkbox controls to show/hide the total playing time and the status (methods of MediaPlayer class). Use 2 RadioButton controls to change background colors (red or blue). The media player should implement the following functional controls
play
stop
volume up
volume down
I this code will help you
this is a simple media player
code:
==================================
package javafxapplication2;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.io.File;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
public class JavaFXApplication2 extends Application {
@Override
public void start(Stage primaryStage)throws Exception {
String path = "";
Label user_id=new Label("MP3 Path ");
TextField tf1=new TextField();
Button b = new Button("Play");
b.setOnAction(e->path=tf1.getText());
GridPane root = new GridPane();
root.addRow(0, user_id, tf1);
root.addRow(2, b);
//Instantiating Media class
Media media = new Media(new File(path).toURI().toString());
//Instantiating MediaPlayer class
MediaPlayer mediaPlayer = new MediaPlayer(media);
//by setting this property to true, the audio will be played
mediaPlayer.setAutoPlay(true);
primaryStage.setTitle("Playing Audio");
primaryStage.show();
Scene scene = new Scene(root, 800, 650);
primaryStage.setTitle("Media Player");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}