import java.io.File; import java.io.IOException; import org.jcodec.api.JCodecException; 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.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaPlayer.Status; import javafx.scene.media.MediaView; import javafx.stage.Stage; import javafx.stage.FileChooser; import javafx.stage.FileChooser.ExtensionFilter; //import JCodec.*; public class Main extends Application implements EventHandler { public static void main(String[] args) { launch(args); } MediaPlayer mediaPlayer, outputPlayer; Button play, play2, edit, preview, preview2; MediaView mediaView2; boolean sceneTwo, edited; //@Override //not sure what this does yet public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Assignment 4: Video Processor"); //buttons play = new Button("\u25B6"); //play.setTranslateX(0-350); play.setTranslateY(420); play.setPrefSize(500, 100); play.setStyle("-fx-font: 24 arial;"); play2 = new Button("\u25B6"); play2.setTranslateY(420); play2.setPrefSize(500, 100); play2.setStyle("-fx-font: 24 arial;"); edit = new Button("Apply Filter (this may take a while)"); edit.setTranslateX(0-400); edit.setTranslateY(420); preview = new Button("Preview Output"); preview.setTranslateX(350); preview.setTranslateY(420); preview2 = new Button("Back to input video"); preview2.setTranslateX(350); preview2.setTranslateY(420); //Choosing media file and displaying the media File video; FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Choose File (Currently only supports mp4 files)"); fileChooser.getExtensionFilters().addAll(new ExtensionFilter("mp4 Video Files", "*.mp4")); video = fileChooser.showOpenDialog(primaryStage); Media media = new Media(video.toURI().toString()); //create the player mediaPlayer = new MediaPlayer(media); MediaView mediaView = new MediaView(mediaPlayer); //Play and pause events for play button - explicitly declared in handle function play.setOnAction(this::handle); //Play and pause events for the play2 button, handling the outputPlayer play2.setOnAction(e -> { if(edited) { if(outputPlayer.getStatus() == Status.PLAYING) { outputPlayer.pause(); play2.setText("\u25B6"); } else { outputPlayer.play(); play2.setText("II"); } } else { play2.setText("There is no output to display!"); } }); //video processing event for the process video button edited = false; edit.setOnAction(e -> { try { edit.setText(getFrames.encoded); getFrames.editVideo(video); edited = true; edit.setText("Done!"); } catch (IOException e1) { //Eclipse Auto-generated catch block e1.printStackTrace(); } catch (JCodecException e1) { //Eclipse Auto-generated catch block e1.printStackTrace(); } }); //Layout and scene StackPane layout = new StackPane(); layout.getChildren().addAll(mediaView, play, edit, preview); Scene scene = new Scene(layout, 1680, 1050); StackPane layout2 = new StackPane(); Scene scene2 = new Scene(layout2, 1680, 1050); //scene switching events for preview button preview.setOnAction(e -> { mediaPlayer.pause(); if(edited) { //create the player for the output video File output = new File("output.mp4"); Media outputMedia = new Media(output.toURI().toString()); outputPlayer = new MediaPlayer(outputMedia); mediaView2 = new MediaView(outputPlayer); layout2.getChildren().add(mediaView2); } //mediaView.setMediaPlayer(outputPlayer); primaryStage.setScene(scene2); }); preview2.setOnAction(e -> { if(edited) { outputPlayer.pause(); } //mediaView.setMediaPlayer(mediaPlayer); primaryStage.setScene(scene); }); layout2.getChildren().addAll(play2, preview2); //putting the scene in the stage and showing the stage primaryStage.setScene(scene); sceneTwo = false; primaryStage.show(); } @Override public void handle(ActionEvent event) { if(mediaPlayer.getStatus() == Status.PLAYING) { mediaPlayer.pause(); play.setText("\u25B6"); } else { mediaPlayer.play(); play.setText("II"); } } }