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)

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.beans.property.*;
import javafx.beans.binding.*;
import javafx.scene.paint.Color;
import javafx.util.Duration;

// public class, public constructor as per JavaFX requirements
public sclass VideoPlayer extends Application {
  static S arg; // path of file to play
  
  File file;
  
  static MediaPlayer theMediaPlayer;
  
  public void start(Stage stage) ctex {
    file = new File(arg);
    
    // Create and set the Scene.
    // Numbers are window size (content is not scaled)
    double w = 540, h = 209;
    new BorderPane root;
    Scene scene = new Scene(root, w, h, Color.BLACK);
    stage.setScene(scene);

    // Name and display the Stage.
    stage.setTitle(file.getName() + " - JavaX Video Player");
    stage.show();

    // Create the media source.
    Media media = new Media(file.toURI().toURL().toString());

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

    // Create the media view.
    MediaView mediaView = new MediaView(mediaPlayer);
    
    // Resize Hack
    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);
  }
  
  public void stop() {
    print("Application stopped.");
  }
}

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: 637 / 986
Referenced in: [show references]