-
Notifications
You must be signed in to change notification settings - Fork 92
/
MediaExample.java
43 lines (32 loc) · 1.31 KB
/
MediaExample.java
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
package com.jenkov.javafx.media;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import java.io.File;
import java.net.MalformedURLException;
/**
* Shows a simple JavaFX Media, MediaPlayer and MediaView example, playing an MP4 video. Please note that the
* video is downloaded from Pixabay.com. Please do not redistribute the video for any purpose. Download it from Pixabay
* if you want to use it:
*
* https://pixabay.com/videos/golden-particles-overlay-decoration-48569/
*/
public class MediaExample extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) throws MalformedURLException {
File mediaFile = new File("assets/media/Golden-48569.mp4");
Media media = new Media(mediaFile.toURI().toURL().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
MediaView mediaView = new MediaView(mediaPlayer);
Scene scene = new Scene(new Pane(mediaView), 1024, 800);
primaryStage.setScene(scene);
primaryStage.show();
mediaPlayer.play();
}
}