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.
Hiç yorum yok:
Yorum Gönder