Planet JFX

Video Example

118pages on
this wiki
Add New Page
Talk0 Share

JavaFX Script Media ExampleEdit

It is a compiler version of Enabling Video Files in JavaFX Applications example.

The sample requires Java Media Framework (JMF) library.

import javafx.ui.*;
import javafx.ui.canvas.*;
import javafx.ui.animation.*;


import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JComponent;


import java.lang.System;

public class JavaWidget extends Widget{
    attribute comp: Component;
    protected function createComponent():JComponent{
        var panel = new JPanel();
        return panel;

public class MediaNode extends CompositeNode {
    attribute xpos: Number;
    attribute ypos: Number;
    attribute url: String;
    attribute autoPlay: Boolean;
    public function composeNode(): Node{
        Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
        var player = Manager.createRealizedPlayer(new URL(url));
        if (autoPlay) {
        return Group{
            content: View{
                content: BorderPanel{
                    center: JavaWidget { comp: player.getVisualComponent() }
                    bottom: JavaWidget { comp: player.getControlPanelComponent() }
            transform: Transform.translate(xpos, ypos)
            onMouseDragged: function(e: CanvasMouseEvent) {
                xpos += e.localDragTranslation.x;
                ypos += e.localDragTranslation.y;

Frame {
    title: 'Media Example'
    width: 400
    height: 300
    onClose: function() { System.exit(0); }
    content: Canvas {
        content: [
            xpos: 0.0
            ypos: 0.0
            url: "" 
            autoPlay: true

            xpos: 100.0
            ypos: 100.0
            opacity: 0.5
            url: "" 
            autoPlay: true
    visible: true

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki