ok so i have a mp4 file in my src folder in my project and it work's fine in eclipse but when i export it to a runnable jar file it doesn't work.
public void playRickRoll() throws MalformedURLException {
StackPane spRickRoll = new StackPane();
Stage stage = new Stage();
stage.setResizable(false);
stage.getIcons().add(new Image("60AKG.png"));
// URL videoURL = getClass().getResource("RickRoll.mp4");
// Media media = new Media(videoURL.toString());
File f = new File("src/RickRoll.mp4");
Media media = new Media(f.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
MediaView mediaView = new MediaView();
mediaView.setMediaPlayer(mediaPlayer);
spRickRoll.getChildren().add(mediaView);
stage.setScene(new Scene(spRickRoll, 460, 360));
stage.show();
mediaPlayer.play();
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent arg0) {
mediaPlayer.stop();
}
});
}
Related
I'm using a translator.
enter image description here
Windows desktop appears unexpectedly when you click on the image.
Scrollpane -> BorderPane
Normal at first Occurs like an image later
FXMLLoader loader = new FXMLLoader(getClass().getResource("/View/Main_fx.fxml"));
Parent root = loader.load();
st = new Stage();
final UndecoratorScene undecorator = new UndecoratorScene(st, (Region) root);//NewMainScene lib 사용(프로젝트 및 패키지 명 :Newtable)
undecorator.getStylesheets().add(getClass().getResource("/View/winDec.css").toExternalForm());
st.setScene(undecorator);
stage = (Stage) lb.getScene().getWindow();
st.getIcons().add(new Image(config2.class.getResourceAsStream("/View/207411.jpg" )));
st.initStyle(StageStyle.TRANSPARENT); //스타일 미적용.
st.setResizable(resize);
st.setMaximized(maximized);
st.setTitle(judul);
st.sizeToScene();
// Undecorator undecor = undecorator.getUndecorator();
//최소로 줄이수 있는 화면 크기 값 .
st.setMinWidth(350);
st.setMinHeight(200);
GetStage gs = new GetStage();//트레이 창으로 보낼때 현재 Stage 값 전달.
gs.SetStage(st);
st.toFront();
st.show();
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
st.setX((primScreenBounds.getWidth() - st.getWidth()) / 2);
st.setY((primScreenBounds.getHeight() - st.getHeight()) / 2);
createTrayIcon(st);//트레이 창 이벤트 메소드
firstTime = true;
Platform.setImplicitExit(false);
stage.close();//controllSplash stage 종료
Hander_Main controller = (Hander_Main)loader.getController();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
Date sys_date = new Date();
String now= formatter.format(sys_date);
controller.setPrimaryStage(st);
controller.setScene(undecorator);
controller.setFirstDate(now);
st.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we)
{
hide(st);
}
});
} catch (Exception e) {
st.hide();
dialog(Alert.AlertType.ERROR,"Main_fx Stage ERR\n"+e);
System.exit(0);
}
First i am sorry for my poor english...
i made Media Player Application with Javafx.
this player can get mulit file media. and play files out of all limits.
it work well. but sometimes not work..
it is not media error. it is mediaplayer error.
error message is 'mediaPlayer Unknown, media Invalid..' why.??
i played same video file(1920 * 1080), sometimes work and sometimes not work..
and javafx is depend on OS ??
player works perfectly on windown7 computer
but player have this error on windown10 computer...
please give me advice..
MediaPlayer mediaPlayer = null;
Stage stage = new Stage();
AnchorPane pane = new AnchorPane();
Scene scene = new Scene(pane);
MediaView mediaView = new MediaView();
int mNextFileIndex = -1;
List<File> fileLists = new ArrayList<>();
Media media;
mediaplayer play Method
public void playNextMedia() {
if (mediaPlayer != null) {
mediaPlayer.dispose();
mediaView.setMediaPlayer(null);
}
mNextFileIndex = (mNextFileIndex + 1) % fileLists.size();
media =new Media(fileLists.get(mNextFileIndex).toURI().toString());
media.setOnError(()-> {
MainApp.makeLog("media error");
});
mediaPlayer = new MediaPlayer(media);
mediaView.setMediaPlayer(mediaPlayer);
mediaPlayer.setOnReady(() -> {
mediaPlayer.play();
});
mediaPlayer.setOnEndOfMedia(() -> {
playNextMedia();
});
mediaPlayer.setOnError(() -> {
systom.out.println("mediaPlayer error");
Systeom.out.println(mediaPlayer.getError().getMessage());
playNextMedia();
});
}
Button Method
#FXML
private void playMedia(ActionEvent event) {
mNextFileIndex = -1;
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(new
FileChooser.ExtensionFilter("Select a File (*.mp4)", "*.mp4"),
new FileChooser.ExtensionFilter("All Files", "*.*"));
List<File> list = fileChooser.showOpenMultipleDialog(null);
if (list != null) {
for (File file : list) {
fileLists.add(file)
}
playNextMedia();
pane.getChildren().add(mediaView);
stage.setScene(scene);
stage.show();
}
please i am trying to settext on a textfield after it as been open from login window but the changes it not displaying pls am new to java and javafx below is the code wich open the new window
try {
Statement stmnt= conn.createStatement();
rs=stmnt.executeQuery(sql);
if(rs.next()==true){
String name = null;
Image img = null;
name = rs.getString("name");
img = new Image(rs.getBinaryStream("photo"));
System.out.println(name);
Stage primaryStage = new Stage();
/*FXMLLoader loader = new FXMLLoader();
Pane root = loader.load(getClass().getResource("main.fxml").openStream());
mainController mnctrl = (mainController) loader.getController();
mnctrl.dispOpInfo(name, img);*/
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("main.fxml"));
Parent root = (Parent)fxmlLoader.load();
mainController controller = fxmlLoader.<mainController>getController();
controller.dispOpInfo(name, img);
primaryStage.show();
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("BECE 2017 Validation");;
primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
primaryStage.show();
//
}
and below is the code for the newly open window of it textfield is not changing at runtime
#FXML TextField txtSchName = new TextField();
public void populateCanInfo (String canSchool, String canName, String canState,String canGender, Image canPhoto){
System.out.println(canGender );
txtCanName.setText(canName);
txtSchName.setText(canSchool);
imgViewCan.setImage(canPhoto);
// int index=cmbCanState.getValue().indexOf(canState);
// cmbCanState.getSelectionModel().select(index);
if(canGender.equalsIgnoreCase(canGender)){
rbtMale.setSelected(true);
}else{
rbtFemale.setSelected(true);
}
}
I tryed to play follwing streams:
url: "http://icecast.unitedradio.it/Radio105.mp3", codec: "mp3"
url: "http://shoutcast.radio24.it:8000/", codec: "AAC"
using the MediaPlayer of JavaFX.
This is the code:
Media media = new Media("http://icecast.unitedradio.it/Radio105.mp3");
MediaPlayer mediaPlayer = new MediaPlayer(media);
MediaView mediaView = new MediaView(mediaPlayer);
mediaView.setFitHeight(500);
mediaView.setFitWidth(500);
mediaPlayer.setVolume(new Double(1));
root.getChildren().add(mediaView);
Button playButton = new Button();
playButton.setOnMouseClicked(new EventHandler<javafx.scene.input.MouseEvent>()
{
#Override
public void handle(javafx.scene.input.MouseEvent event)
{
mediaPlayer.play();
}
});
root.getChildren().add(playButton);
primaryStage.setScene(scene);
primaryStage.show();
But pressing the playbutton the audio does not play.
Debugging the Media I have found that using one of stream above, in the Locator.init() the contentLength is -1. May be this the reason why it does not play?
I have a small test a JButton in a SwingNode in a Stage, using Java 8.
Problem: right click is not triggered, the middle click is interpreted as right click ...
Here is the code:
Platform.runLater(new Runnable() {
#Override
public void run() {
HBox hb = new HBox();
SwingNode n = new SwingNode();
JButton b = new JButton("CLICK ME!!!");
b.addMouseListener(new MouseAdapter() {
public final void mousePressed(MouseEvent e) {
boolean isLeftClick = SwingUtilities.isLeftMouseButton(e);
boolean isRightClick = SwingUtilities.isRightMouseButton(e);
if (isLeftClick)
System.out.println("Left");
if (isRightClick)
System.out.println("Right");
}
});
n.setContent(b);
hb.getChildren().add(n);
Stage stage = new Stage();
Scene appScene = new Scene(hb,100, 100);
stage.setScene(appScene);
stage.show();
}
});