ADDITIONAL SYSTEM INFORMATION :
Windows 11 (Version 10.0.22621) (Windows 11 was not an option in the form so I picked 10 instead)
Oracle JDK 19 (build 19.0.2+7-44)
A DESCRIPTION OF THE PROBLEM :
When using a MediaPlayer and it is disposed and replaced repeatedly it sometimes does not start playing. There are no error logs even with `javafx.verbose=true`. The only logs I see is on startup where it loads DLL files from resources rather than from ".m2/repository". I am pretty sure this issue arose after I switched to Windows 11.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code pasted in "Source code for an executable test case". It expects a resource file called "video.mp4". I recommend testing with a small video. Main#start() initializes JFX and the player. Main#reinit() is called twice per second and disposes the old player and creates a new one. After 3-10 restarts the video never starts playing and it will print "stuck!" repeatedly. If I remove the stuck check and let it keep reinitializing, it will start working again.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The video should keep restarting forever.
ACTUAL -
After a few restarts, nothing happens. The screen is white and the video never starts.
---------- BEGIN SOURCE ----------
package org.example;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class Main implements ActionListener {
private Timer timer = new Timer(500, this);
private MediaView viewer;
private boolean prevStarted = true;
public static void main(String[] args) {
new Main().start();
}
private void start() {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JFXPanel jfxPanel = new JFXPanel();
frame.setMinimumSize(new Dimension(500, 500));
frame.add(jfxPanel);
frame.pack();
frame.setVisible(true);
viewer = new MediaView();
viewer.setFitWidth(500);
viewer.setFitHeight(500);
viewer.setPreserveRatio(true);
StackPane pane = new StackPane();
pane.getChildren().add(viewer);
jfxPanel.setScene(new Scene(pane, 500, 500));
timer.setInitialDelay(100);
timer.start();
});
}
private void reinit() {
if (!prevStarted) {
System.out.println("stuck!");
return;
}
prevStarted = false;
MediaPlayer oldPLayer = viewer.getMediaPlayer();
if (oldPLayer != null) {
oldPLayer.dispose();
}
MediaPlayer newPlayer = new MediaPlayer(new Media(new File("src/main/resources/video.mp4").toURI().toString()));
newPlayer.setVolume(0);
newPlayer.setOnPlaying(() -> {
prevStarted = true;
});
newPlayer.play();
viewer.setMediaPlayer(newPlayer);
}
@Override
public void actionPerformed(ActionEvent e) {
reinit();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Detect somehow that OnPlaying is never executed within x ms. If it has not started within that timeframe, replace the MediaPlayer and dispose the old one.
FREQUENCY : often
Windows 11 (Version 10.0.22621) (Windows 11 was not an option in the form so I picked 10 instead)
Oracle JDK 19 (build 19.0.2+7-44)
A DESCRIPTION OF THE PROBLEM :
When using a MediaPlayer and it is disposed and replaced repeatedly it sometimes does not start playing. There are no error logs even with `javafx.verbose=true`. The only logs I see is on startup where it loads DLL files from resources rather than from ".m2/repository". I am pretty sure this issue arose after I switched to Windows 11.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code pasted in "Source code for an executable test case". It expects a resource file called "video.mp4". I recommend testing with a small video. Main#start() initializes JFX and the player. Main#reinit() is called twice per second and disposes the old player and creates a new one. After 3-10 restarts the video never starts playing and it will print "stuck!" repeatedly. If I remove the stuck check and let it keep reinitializing, it will start working again.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The video should keep restarting forever.
ACTUAL -
After a few restarts, nothing happens. The screen is white and the video never starts.
---------- BEGIN SOURCE ----------
package org.example;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class Main implements ActionListener {
private Timer timer = new Timer(500, this);
private MediaView viewer;
private boolean prevStarted = true;
public static void main(String[] args) {
new Main().start();
}
private void start() {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JFXPanel jfxPanel = new JFXPanel();
frame.setMinimumSize(new Dimension(500, 500));
frame.add(jfxPanel);
frame.pack();
frame.setVisible(true);
viewer = new MediaView();
viewer.setFitWidth(500);
viewer.setFitHeight(500);
viewer.setPreserveRatio(true);
StackPane pane = new StackPane();
pane.getChildren().add(viewer);
jfxPanel.setScene(new Scene(pane, 500, 500));
timer.setInitialDelay(100);
timer.start();
});
}
private void reinit() {
if (!prevStarted) {
System.out.println("stuck!");
return;
}
prevStarted = false;
MediaPlayer oldPLayer = viewer.getMediaPlayer();
if (oldPLayer != null) {
oldPLayer.dispose();
}
MediaPlayer newPlayer = new MediaPlayer(new Media(new File("src/main/resources/video.mp4").toURI().toString()));
newPlayer.setVolume(0);
newPlayer.setOnPlaying(() -> {
prevStarted = true;
});
newPlayer.play();
viewer.setMediaPlayer(newPlayer);
}
@Override
public void actionPerformed(ActionEvent e) {
reinit();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Detect somehow that OnPlaying is never executed within x ms. If it has not started within that timeframe, replace the MediaPlayer and dispose the old one.
FREQUENCY : often
- is blocked by
-
JDK-8331458 Replace qtdemux with MP4 demux based on Media Foundation
- In Progress