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).

!7

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.layout.*;
import javafx.beans.property.*;
import javafx.beans.binding.*;

p-awt {
  jfxFastVideo();
  
  JFrame frame = showFrame();
  final new JFXPanel fxPanel;
  frame.add(fxPanel);

  jfxLater(r {
    fxPanel.setScene(createScene());
  });
}

// JavaFX World
static Scene createScene() {
  new BorderPane root;
  Scene scene = new Scene(root, Color.ALICEBLUE);

  // Create the media source.
  //String source = getParameters().getRaw().get(0);
  String source = "/home/stefan/Downloads/Mission Impossible (2000)/Mission.Impossible.II.2000.720p.BrRip.x264-YIFY.mp4";
  Media media = null;
  try {
    media = new Media(new File(source).toURI().toURL().toString());
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }

  // Create the player and set to play automatically.
  MediaPlayer mediaPlayer = new MediaPlayer(media);
  mediaPlayer.setAutoPlay(true);

  // Create the view and add it to the Scene.
  MediaView mediaView = new MediaView(mediaPlayer);
  
  // Crappy hack from here: http://stackoverflow.com/questions/25090378/how-do-i-make-javafx-mediaview-stretch-media-to-fill-parent-container
  // mediaView.fitWidthProperty().bind(mediaPlayer.widthProperty());
  
  // Another hack from the same page.
  DoubleProperty mvw = mediaView.fitWidthProperty();
  DoubleProperty mvh = mediaView.fitHeightProperty();
  mvw.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"));
  mvh.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"));
  mediaView.setPreserveRatio(true);
  
  root.setCenter(mediaView);
  ret scene;
}

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: 1080 / 1038
Version history: 2 change(s)
Referenced in: [show references]