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

63
LINES

< > BotCompany Repo | #1003704 // Try Putting JavaFX Video in Swing JFrame And Resizing It Automatically

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

Libraryless. Click here for Pure Java version (5022L/36K/130K).

1  
!7
2  
3  
import javafx.application.Platform;
4  
import javafx.embed.swing.JFXPanel;
5  
import javafx.scene.Group;
6  
import javafx.scene.Scene;
7  
import javafx.scene.paint.Color;
8  
import javafx.scene.text.Font;
9  
import javafx.scene.text.Text;
10  
import javafx.scene.media.Media;
11  
import javafx.scene.media.MediaPlayer;
12  
import javafx.scene.media.MediaView;
13  
import javafx.scene.layout.*;
14  
import javafx.beans.property.*;
15  
import javafx.beans.binding.*;
16  
17  
p-awt {
18  
  jfxFastVideo();
19  
  
20  
  JFrame frame = showFrame();
21  
  final new JFXPanel fxPanel;
22  
  frame.add(fxPanel);
23  
24  
  jfxLater(r {
25  
    fxPanel.setScene(createScene());
26  
  });
27  
}
28  
29  
// JavaFX World
30  
static Scene createScene() {
31  
  new BorderPane root;
32  
  Scene scene = new Scene(root, Color.ALICEBLUE);
33  
34  
  // Create the media source.
35  
  //String source = getParameters().getRaw().get(0);
36  
  String source = "/home/stefan/Downloads/Mission Impossible (2000)/Mission.Impossible.II.2000.720p.BrRip.x264-YIFY.mp4";
37  
  Media media = null;
38  
  try {
39  
    media = new Media(new File(source).toURI().toURL().toString());
40  
  } catch (MalformedURLException e) {
41  
    throw new RuntimeException(e);
42  
  }
43  
44  
  // Create the player and set to play automatically.
45  
  MediaPlayer mediaPlayer = new MediaPlayer(media);
46  
  mediaPlayer.setAutoPlay(true);
47  
48  
  // Create the view and add it to the Scene.
49  
  MediaView mediaView = new MediaView(mediaPlayer);
50  
  
51  
  // Crappy hack from here: http://stackoverflow.com/questions/25090378/how-do-i-make-javafx-mediaview-stretch-media-to-fill-parent-container
52  
  // mediaView.fitWidthProperty().bind(mediaPlayer.widthProperty());
53  
  
54  
  // Another hack from the same page.
55  
  DoubleProperty mvw = mediaView.fitWidthProperty();
56  
  DoubleProperty mvh = mediaView.fitHeightProperty();
57  
  mvw.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
58  
  mvh.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
59  
  mediaView.setPreserveRatio(true);
60  
  
61  
  root.setCenter(mediaView);
62  
  ret scene;
63  
}

Author comment

Began life as a copy of #1003703

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
1259 stefan Well, now it centers the video. 2016-07-26 00:12:20

add comment

Snippet ID: #1003704
Snippet name: Try Putting JavaFX Video in Swing JFrame And Resizing It Automatically
Eternal ID of this version: #1003704/3
Text MD5: c26559e8f6f957faf3115cf66225d9b6
Transpilation MD5: d6c788783faa25ddab25e8ca85ba485a
Author: stefan
Category: javax / javafx
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-31 00:30:40
Source code size: 1990 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 988 / 928
Version history: 2 change(s)
Referenced in: [show references]