javafx etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
javafx etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

6 Nisan 2011 Çarşamba

JavaFX MediaBox exception: Connection refused: connect.


Problem
When you build the JavaFX MediaBox component (or a modified version of it), Netbeans 6.9.1 ide produces the following files under dist folder.
MediaBox.html
MediaBox.jar
MediaBox.jar.pack.gz
MediaBox.jnlp
MediaBox_browser.jnlp

When you move those files to production environment (some other location or a web server), you may get the following error, when you try to see MediaBox.html via a browser.

exception: Connection refused: connect.
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
.....
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.net.ConnectException: Connection refused: connect

Solution
In my case, this was due to .jnlp files.
Editing codebase and homepage attributes accordingly in both MediaBox.jnlp and MediaBox_browser.jnlp files fixed the issue.


31 Mart 2011 Perşembe

revisited: using Java FX app in a web application

Please read for the background of this post: http://hilaltarakci.blogspot.com/2011/03/using-java-fx-app-in-web-application.html

Unfortunately, JavaFX MediaBox component did not run successfully, when i deployed the web application in production environment and test it from another client computer.
After a while, i realized that the problem is due to calling JavaFX from a .jsp file.. When JavaFX MediaBox is called from an .html file, no problem shows up..

28 Mart 2011 Pazartesi

using Java FX app in a web application

In order to pass media url as argument to Java FX MediaBox component,
  • change the Main.fxin MediaBox project as follows:
var mediaUrl = FX.getArgument("mediaUrl");

// in order to access mediaUrl, use mediaUrl.toString()
  • create a java web application project (i used Netbeans 6.5.1 for this).
  • edit index.jsp as follows:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script src="http://dl.javafx.com/dtfx.js"></script>
<script>
javafx(
{
archive: "MediaBox.jar",
width: 640,
height: 360,
code: "com.sun.javafx.mediabox.Main",
name: "MediaBox"
}, {
mediaUrl: "http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2956241001_big-buck-bunny-640x360.flv"
/*"file:/E:/htarakci/WORKSTATION/tez/projects/lost.avi"*/
}
);
</script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
  • deploy the web app to server and run..

javafx samples here:

for deploying Javafx app:

for passing arguments to Javafx app:

a few tips on writing scripts:

display video interval (specifying startTime and stopTime) with JavaFX Media Box

JavaFX Media Box Component is a prefabricated video player.

In order to play a specified interval of the given video, slightly modify original Main.fx code as follows:
package com.sun.javafx.mediabox;

import javafx.stage.*;
import javafx.scene.*;
import com.sun.javafx.mediabox.MediaBox;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;

/**
* @author baechul
*/

var mediaUrl = //"file:/C:/hilaltarakci/WORKSTATION/workspace/WebClient/lost.avi";
"http://sun.edgeboss.net/download/sun/media/1460825906/1460825906_2956241001_big-buck-bunny-640x360.flv";

var mediaTitle = "Lost Movie Sample";
var mediaDescription = "a sample scene from loast movie...";

var startTime = 404444;
var stopTime = 424444;

var theme = getFXArgString("theme", "paranara");
var mediaViewWidth = getFXArgInt("mediaViewWidth", 640);
var mediaViewHeight = getFXArgInt("mediaViewHeight", 360);

var mediaBox:MediaBox = MediaBox {

// set the current profile

// media and play variables
mediaSource:mediaUrl
mediaTitle: mediaTitle
mediaDescription: mediaDescription
autoPlay: true // default: false
preserveRatio: true // default: true

// size and layout position
width: bind mediaBox.scene.width
//width: bind if({__PROFILE__} == "desktop") 640 else 1024;

height: bind mediaBox.scene.height
//height: bind if({__PROFILE__} == "desktop") 360 else 1024;
layoutX: 0;
layoutY: 0;

// view
themeStr: theme // default: "paranara"
mediaControlBarHeight: 25 // default: 25, possible values: 20~50
showMediaInfo: true // default: true

// function variables
onMouseClicked: function(me) {
mediaBox.setVideo(mediaUrl, mediaTitle, mediaDescription, startTime, stopTime);
/*mediaBox.mediaControlBar.mediaPlayer.startTime = Duration.valueOf(startTime);
mediaBox.mediaControlBar.mediaPlayer.stopTime = Duration.valueOf(stopTime);*/
}

onKeyPressed:function(e:KeyEvent):Void {
if ((e.code == KeyCode.VK_BACK_SPACE) or
(e.code == KeyCode.VK_Q) or
(e.code == KeyCode.VK_POWER))
{
FX.exit();
}
}
}

Stage {
title: "MediaBox Player"
resizable: true

scene:Scene {
//width: getFXArgInt("mediaViewWidth", 640)
width: getWidth()
//height: getFXArgInt("mediaViewHeight", 360)
height: getHeight()
content: mediaBox
}
}

mediaBox.requestFocus();

// helper functions

function getWidth(): Number {

if ({__PROFILE__} == "desktop")
return 640
else
return 1280
}

function getHeight(): Number {

if ({__PROFILE__} == "desktop")
return 360
else
return 720
}

function getFXArgString(arg:String, defaultValue:String): String {
var val = FX.getArgument(arg);
if (val == null) {
return defaultValue;
}
return val as String;
}

function getFXArgInt(arg:String, defaultValue:Integer): Integer {
var val = FX.getArgument(arg);
if (val == null) {
return defaultValue;
}
try {
return Integer.parseInt(val as String);
} catch (nfe: java.lang.NumberFormatException) {
return defaultValue;
}
}

and add the following method to the end of MediaBox.fx :

public function setVideo(url: String, title: String, description: String,
givenStartTime: Integer, givenStopTime: Integer) {
mediaSource = url;
mediaTitle = title;
mediaDescription = description;
mediaControlBar.mediaPlayer.startTime = Duration.valueOf(givenStartTime);
mediaControlBar.mediaPlayer.stopTime = Duration.valueOf(givenStopTime);
}

The application is going to play the video from the beginning at first. However, when you click on the video, the video will play the specified interval.