JavaFx Multiple Media Player

sebelumnya minta maaf, karena artikel ini tidak di publish tepat waktu; hari ini “agak kacau”, sehingga nulis blogpun jadi tidak sempat ;) . dan karena itu, nulis artikelnya juga males :p, langsung publish source code-nya saja ya, nanti semoga ada kesempatan lain untuk menuliskan artikelnya. tapi jangan kuatir, codenya sangat clean, jadi sangat mudah dipahami :D

file: Main.fx

def mymp1 = MyMediaPlayer{
    mediaURL: "file:///F:/Harmony.flv"
    width: 200
    height: 150
    translateX: 10
}

def mymp2 = MyMediaPlayer{
    mediaURL: "file:///F:/Movies/video6.flv"
    width: 200
    height: 150
    translateX: 300
}

def scene = Scene {
    content: [mymp1,mymp2]/*HBox{
        translateY : 20
        spacing: 100
        content:[mymp1,mymp2]}//playerGroup;*/
}

def stage:Stage = Stage {
    title: "MyApp"
    scene: scene
    width: bind width with inverse
    height: bind height with inverse
    fullScreen : bind isfullscreen with inverse
    //style : bind stagestyle with inverse
}

file: myMediaPlayer.fx


/*
 * MyMediaPlayer.fx
 *
 * Created on 23 Mar 09, 23:39:24
 */

package mymediaplayer;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.Group;
import javafx.scene.media.MediaView;
import javafx.ext.swing.SwingButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
/**
 * @author Hakim
 */

public class MyMediaPlayer extends CustomNode{
    public var mediaURL:String = "";
    public var width:Number = 500;
    public var height:Number = 300;
    var isfullscreen:Boolean = false;
    public var maxX = 200.0;
    public var maxY = 200.0;
    var startX = 0.0;
    var startY = 0.0;

    override function create():Node{
        return Group{
            content: [mv, buttonGroup]
            onMouseClicked: mouseClicked
        }
    }

    def media = Media {
        source: mediaURL
    }

    def mp = MediaPlayer {
        media: media
        autoPlay: false
    }

    def mv = MediaView {
        preserveRatio: false
        mediaPlayer: mp
        preserveRatio : false;
        fitWidth : bind width;
        fitHeight: bind height;
    }

    function play():Void{
        mp.play();
    }

    function pause():Void{
        mp.pause();
    }

    function stop():Void{
        mp.stop();
    }

    def buttonPlay = SwingButton {
        text: "Play"
        action: play
    }

    def buttonPause = SwingButton {
        text: "Pause"
        action: pause
    }

    def buttonStop = SwingButton {
        text: "Stop"
        action: stop
    }

    function fullScreen(){
        isfullscreen = not isfullscreen;
    }

    function mouseClicked(e:MouseEvent){
        if (e.clickCount == 2){
            fullScreen();
        }
    }

    def buttonGroup = HBox{
        content: [buttonPlay, buttonPause, buttonStop]
        translateX: bind (width - buttonPlay.boundsInParent.width*3)/2;
    }

    override var onMousePressed = function(e:MouseEvent):Void {
        startX = e.sceneX-translateX;
        startY = e.sceneY-translateY;
    }

    override var onMouseDragged = function(e:MouseEvent):Void {
        var tx = e.sceneX-startX;
        translateX = tx;

        var ty = e.sceneY-startY;
        translateY = ty;
    }
}

media playernya bersifat draggable, sehingga bisa di drag dari posisi awal.
screenshotnya:
multiplemediaplayer

3 thoughts on “JavaFx Multiple Media Player

  1. maz mau tny lg ya…tp ni kelanjutan topik diatas

    file(script) bwt koneksi mysql ke java bisa digunakan bwt koneksi javafx ke mysql jg ga???

    trs untuk koneksi javafx ke mysql, bikin file(script)nya java di aplikasi javafx atau java byasa??

    klo bs dikasih tutorialnya koneksi javafx k mysql..

    makasih

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s