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

84
LINES

< > BotCompany Repo | #1003706 // JavaFX: Try Adding Buttons To Video And Auto-Resizing

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (131L/2K/5K).

1  
!759
2  
3  
import javafx.application.Application;
4  
import javafx.scene.Group;
5  
import javafx.scene.Scene;
6  
import javafx.scene.media.Media;
7  
import javafx.scene.media.MediaPlayer;
8  
import javafx.scene.media.MediaView;
9  
import javafx.stage.Stage;
10  
import javafx.scene.layout.*;
11  
import javafx.geometry.Insets;
12  
import javafx.scene.control.Button;
13  
import javafx.beans.property.*;
14  
import javafx.beans.binding.*;
15  
16  
public class main extends Application {
17  
  p {
18  
    System.setProperty("prism.forceGPU", "true");
19  
    System.setProperty("prism.verbose", "true");
20  
    
21  
    fixContextClassLoader();
22  
    launch();
23  
  }
24  
25  
  public void start(Stage stage) {
26  
    // Create and set the Scene.
27  
    // Numbers are window size (content is not scaled)
28  
    double w = 540, h = 209;
29  
    Scene scene = new Scene(new Group(), w, h);
30  
    stage.setScene(scene);
31  
32  
    // Name and display the Stage.
33  
    stage.setTitle("Hello Media");
34  
    stage.show();
35  
36  
    // Create the media source.
37  
    //String source = getParameters().getRaw().get(0);
38  
    String source = "/media/CE009E97009E865D__/Downloads/Oblivion (2013)/Oblivion.2013.mp4";
39  
    Media media = null;
40  
    try {
41  
      media = new Media(new File(source).toURI().toURL().toString());
42  
    } catch (MalformedURLException e) {
43  
      throw new RuntimeException(e);
44  
    }
45  
46  
    // Create the player and set to play automatically.
47  
    MediaPlayer mediaPlayer = new MediaPlayer(media);
48  
    mediaPlayer.setAutoPlay(true);
49  
50  
    // Create the media view.
51  
    MediaView mediaView = new MediaView(mediaPlayer);
52  
    
53  
    // Resize Hack
54  
    DoubleProperty mvw = mediaView.fitWidthProperty();
55  
    DoubleProperty mvh = mediaView.fitHeightProperty();
56  
    mvw.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
57  
    mvh.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
58  
    mediaView.setPreserveRatio(true);
59  
  
60  
  // Make BorderPane and add to scene.
61  
    BorderPane border = new BorderPane();
62  
    HBox hbox = makeButtons();
63  
    border.setBottom(hbox);
64  
    border.setCenter(mediaView);
65  
    
66  
    ((Group) scene.getRoot()).getChildren().add(border);
67  
  }
68  
  
69  
  HBox makeButtons() {
70  
    new HBox hbox;
71  
    hbox.setPadding(new Insets(15, 12, 15, 12));
72  
    hbox.setSpacing(10);
73  
    hbox.setStyle("-fx-background-color: #336699;");
74  
75  
    Button buttonCurrent = new Button("Current");
76  
    buttonCurrent.setPrefSize(100, 20);
77  
78  
    Button buttonProjected = new Button("Projected");
79  
    buttonProjected.setPrefSize(100, 20);
80  
    hbox.getChildren().addAll(buttonCurrent, buttonProjected);
81  
82  
    return hbox;    
83  
  }
84  
}

Author comment

Began life as a copy of #1003700

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
1261 stefan Almost works... just the video is cut off by the buttons. 2016-07-26 00:29:36

add comment

Snippet ID: #1003706
Snippet name: JavaFX: Try Adding Buttons To Video And Auto-Resizing
Eternal ID of this version: #1003706/1
Text MD5: 54fb15f9ab5276fbe21db408d1e46eeb
Transpilation MD5: 768a101a570a0f602928ee4184485216
Author: stefan
Category: javax / javafx
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-26 00:27:49
Source code size: 2604 bytes / 84 lines
Pitched / IR pitched: No / No
Views / Downloads: 716 / 716
Referenced in: [show references]