Fandom

Planet JFX

Video Example

118pages on
this wiki
Add New Page
Talk0 Share

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.

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.net.URL;

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

import javax.media.Manager;

import java.lang.System;


public class JavaWidget extends Widget{
    attribute comp: Component;
    protected function createComponent():JComponent{
        var panel = new JPanel();
        panel.add(comp);
        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) {
            player.start();
        }
        
        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: [
        
        MediaNode{            
            xpos: 0.0
            ypos: 0.0
            
            url: "https://www.dev.java.net/files/documents/6929/89419/test.mov" 
            autoPlay: true
        },

        MediaNode{            
            xpos: 100.0
            ypos: 100.0
            opacity: 0.5
            
            url: "https://www.dev.java.net/files/documents/6929/89418/test.avi" 
            autoPlay: true
        },
        
        ]
    }
    visible: true
}

Also on Fandom

Random Wiki