Advertisement
Guest User

Not able to fix my error

a guest
Mar 8th, 2023
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | Source Code | 0 0
  1. package com.example.testingmedia;
  2.  
  3. import javafx.application.Application;
  4. import javafx.fxml.FXMLLoader;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.layout.GridPane;
  8. import javafx.stage.Stage;
  9. import javafx.scene.media.Media;
  10. import javafx.scene.media.MediaPlayer;
  11. import javafx.scene.media.MediaView;
  12. import java.io.File;
  13. import java.io.IOException;
  14.  
  15. public class HelloApplication extends Application {
  16.     @Override
  17.     public void start(Stage stage) throws IOException {
  18.         FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
  19.         Scene scene = new Scene(fxmlLoader.load(), 320, 240);
  20.         stage.setTitle("Hello!");
  21.         stage.setScene(scene);
  22.         stage.show();
  23.  
  24.         String file = "https://www.youtube.com/watch?v=rcp3tZ3XFyQ";
  25.         Media media = new Media(new File(file).toURI().toString());
  26.         MediaPlayer mediaPlayer = new MediaPlayer(media);
  27.         MediaView mediaView = new MediaView(mediaPlayer);
  28.  
  29.         Button button1 = new Button("Play");
  30.         Button button2 = new Button("Pause");
  31.         Button button3 = new Button("Stop");
  32.  
  33.         button1.setOnAction(e -> {
  34.             mediaPlayer.play();
  35.         });
  36.  
  37.         button2.setOnAction(event -> {
  38.             mediaPlayer.stop();
  39.         });
  40.  
  41.         button3.setOnAction(event -> {
  42.             mediaPlayer.stop();
  43.         });
  44.  
  45.         GridPane layout = new GridPane();
  46.         layout.setHgap(10);
  47.         layout.setVgap(10);
  48.  
  49.         //layout.add(mediaView, 0, 0);
  50.         layout.add(mediaView, 1, 0);
  51.         layout.add(button1, 0, 1);
  52.         layout.add(button2, 1, 1);
  53.         layout.add(button3, 2, 1);
  54.  
  55.         Scene scene1 = new Scene(layout, 300, 200);
  56.  
  57.         stage.setTitle("Coding a MediaView");
  58.         stage.setScene(scene);
  59.         stage.show();
  60.     }
  61.  
  62.     public static void main(String[] args) {
  63.         launch();
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement