Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

62
LINES

< > BotCompany Repo | #1003758 // class VideoPlayer (JavaFX Video Frame)

JavaX fragment (include)

1  
import javafx.application.Application;
2  
import javafx.scene.Group;
3  
import javafx.scene.Scene;
4  
import javafx.scene.media.Media;
5  
import javafx.scene.media.MediaPlayer;
6  
import javafx.scene.media.MediaView;
7  
import javafx.stage.Stage;
8  
import javafx.scene.layout.*;
9  
import javafx.geometry.Insets;
10  
import javafx.scene.control.Button;
11  
import javafx.beans.property.*;
12  
import javafx.beans.binding.*;
13  
import javafx.scene.paint.Color;
14  
import javafx.util.Duration;
15  
16  
// public class, public constructor as per JavaFX requirements
17  
public sclass VideoPlayer extends Application {
18  
  static S arg; // path of file to play
19  
  
20  
  File file;
21  
  
22  
  static MediaPlayer theMediaPlayer;
23  
  
24  
  public void start(Stage stage) ctex {
25  
    file = new File(arg);
26  
    
27  
    // Create and set the Scene.
28  
    // Numbers are window size (content is not scaled)
29  
    double w = 540, h = 209;
30  
    new BorderPane root;
31  
    Scene scene = new Scene(root, w, h, Color.BLACK);
32  
    stage.setScene(scene);
33  
34  
    // Name and display the Stage.
35  
    stage.setTitle(file.getName() + " - JavaX Video Player");
36  
    stage.show();
37  
38  
    // Create the media source.
39  
    Media media = new Media(file.toURI().toURL().toString());
40  
41  
    // Create the player and set to play automatically.
42  
    MediaPlayer mediaPlayer = new MediaPlayer(media);
43  
    theMediaPlayer = mediaPlayer;
44  
    mediaPlayer.setAutoPlay(true);
45  
46  
    // Create the media view.
47  
    MediaView mediaView = new MediaView(mediaPlayer);
48  
    
49  
    // Resize Hack
50  
    DoubleProperty mvw = mediaView.fitWidthProperty();
51  
    DoubleProperty mvh = mediaView.fitHeightProperty();
52  
    mvw.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
53  
    mvh.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
54  
    mediaView.setPreserveRatio(true);
55  
  
56  
    root.setCenter(mediaView);
57  
  }
58  
  
59  
  public void stop() {
60  
    print("Application stopped.");
61  
  }
62  
}

Author comment

Began life as a copy of #1003750

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003758
Snippet name: class VideoPlayer (JavaFX Video Frame)
Eternal ID of this version: #1003758/1
Text MD5: 7fe84863e9bf8beef48cc3a04d277f47
Author: stefan
Category: javax / javafx
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-29 01:07:26
Source code size: 1917 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 564 / 906
Referenced in: [show references]