Using JMC from Java

I have read the following post and understood pattern to use class of JavaFX from the Java language.

I tried to use Java Media Components from Java to play MP3 files and at last I succeeded.
The environment is Windows XP, and JavaFX SDK 1.1 is installed at c:\Program Files\JavaFX\javafx-sdk.
I can agree to the claim that functions of JavaFX are important, but script language is unnecessary. However, the following writing style is redundant. I want to use this technique to reuse resources which I implemented in Java in the past.

// Java MP3 Player using JavaFX JMC classes
// 2009-03-08 by nishimotz@gmail.com
// based on work of Matt Hicks
// http://www.matthicks.com/2009/02/i-hate-javafx-i-love-javafx.html
//
// Requirements (Eclipse 3.4.1)
// To avoid
//   java.lang.UnsatisfiedLinkError:
//   com.sun.media.jmcimpl.plugins.directshow.DShowEngine.ndsInit()
// add jmc.dll as follows:
// Java -> Build Path -> User Library
//   jmc-dll
//   File : C:\Program Files\JavaFX\javafx-sdk\lib\desktop\jmc.dll
//   Location : C:/Program Files/JavaFX/javafx-sdk/lib/desktop
// Notes
//   javafxgui.jar : for javafx.scene.media.*
package test;
import java.io.IOException;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
public class MyMediaPlayer {
	public MyMediaPlayer() throws IOException {
		Media media = new Media(); {
			media.initialize$();
			String mediaUrl = "http://hoge.hoge/hoge.mp3";
			// String mediaUrl = "file:///C:/hoge/hoge.mp3";
			media.$source.set(mediaUrl);
		}
		MediaPlayer mediaPlayer = new MediaPlayer(); {
			mediaPlayer.$media.set(media);
		}
		MediaView mediaView = new MediaView(); {
			mediaView.$mediaPlayer.set(mediaPlayer);
		}
		Scene scene = new Scene(); {
			scene.impl_setWidth(100.0f);
			scene.impl_setHeight(100.0f);
			scene.$content.insert(mediaView);
		}
		Stage stage = new Stage(); {
			stage.$title.set("MyMediaPlayer");
			stage.$scene.set(scene);
		}
		mediaPlayer.play();
	}
	public static void main(String[] args) throws Exception {
		new MyMediaPlayer();
	}
}

The equivalent JavaFX code is as follows:

// based on http://gihyo.jp/dev/serial/01/javafx/0010?page=1
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.media.*;
var mediaUrl:String = "http://hoge.hoge/hoge.mp3";
var theWidth:Number = 100.0;
var theHeight:Number = 100.0;
var media = Media {
    source: mediaUrl
};
var mediaPlayer = MediaPlayer {
    media: media
};
Stage {
    title: "MP3 Player"
    scene: Scene {
        width: theWidth
        height: theHeight
        content: MediaView {
            mediaPlayer: mediaPlayer
        }
    }
}
mediaPlayer.play();

Published by nishimotz

A freelance consultant. doctor of engineering. speech interface, open-source software, accessibility, #nvdajp. Facebook: http://bit.ly/ckUk20