-
Bug
-
Resolution: Unresolved
-
P4
-
8u74
-
x86
-
windows_7
FULL PRODUCT VERSION :
Java Version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
I wrote simple MP3 Player in JavaFX and i found a bug. When i am playing mp3 track with high bitrate (for example 320kb/s), seek() method of MediaPlayer class works inaccurate - the difference between the set time and the reall time of the track depends on the file, it happened, that was up to 30 seconds (for example I set time to 120:00 in seconds, but real time was 90:00). It is very problematic when you try to create a progress bar using Slider, beacause it must be accurate to fine working.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) make a JavaFX project
2) download any file with bitrate 320kb/s (try a few files), I used it: https://drive.google.com/file/d/0Bw_Q7Nm40CvkRVJ6SHItbUFQQTA/view?usp=sharing
(something about 5 second difference between Java player and real time).
3) create an object of Media based of mp3 file.
4) create an object of MediaPlayer based on Media object.
5) use setAutoPlay() method and set it to true
6) create a Button and set action to perform seek() method of MediaPlayer - set it for example to 120 in seconds.
7) listen the moment of song
8) check real moment of song in other player in same time - for example Winamp or Windows Media Player
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
difference between real time and time of track in JavaFX player may be 2-30 seconds, it depends on file
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Main.java:
package application;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Main extends Application implements Initializable {
@FXML
private Button button;
@Override
public void start(Stage primaryStage) {
try {
Parent parent = (Parent) FXMLLoader.load(getClass().getResource(
"/application/MainPane.fxml"));
Scene scene = new Scene(parent);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
File mp3 = new File("320.mp3");
String path = mp3.toURI().toString();
Media media = new Media(path);
final MediaPlayer mp = new MediaPlayer(media);
mp.setAutoPlay(true);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
double position = 120;
mp.seek(Duration.seconds(position));
}
});
}
}
MainPane.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<Button fx:id="button" mnemonicParsing="false" text="change position" />
</children>
</AnchorPane>
---------- END SOURCE ----------
SUPPORT :
YES
Java Version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
I wrote simple MP3 Player in JavaFX and i found a bug. When i am playing mp3 track with high bitrate (for example 320kb/s), seek() method of MediaPlayer class works inaccurate - the difference between the set time and the reall time of the track depends on the file, it happened, that was up to 30 seconds (for example I set time to 120:00 in seconds, but real time was 90:00). It is very problematic when you try to create a progress bar using Slider, beacause it must be accurate to fine working.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) make a JavaFX project
2) download any file with bitrate 320kb/s (try a few files), I used it: https://drive.google.com/file/d/0Bw_Q7Nm40CvkRVJ6SHItbUFQQTA/view?usp=sharing
(something about 5 second difference between Java player and real time).
3) create an object of Media based of mp3 file.
4) create an object of MediaPlayer based on Media object.
5) use setAutoPlay() method and set it to true
6) create a Button and set action to perform seek() method of MediaPlayer - set it for example to 120 in seconds.
7) listen the moment of song
8) check real moment of song in other player in same time - for example Winamp or Windows Media Player
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
difference between real time and time of track in JavaFX player may be 2-30 seconds, it depends on file
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Main.java:
package application;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Main extends Application implements Initializable {
@FXML
private Button button;
@Override
public void start(Stage primaryStage) {
try {
Parent parent = (Parent) FXMLLoader.load(getClass().getResource(
"/application/MainPane.fxml"));
Scene scene = new Scene(parent);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
File mp3 = new File("320.mp3");
String path = mp3.toURI().toString();
Media media = new Media(path);
final MediaPlayer mp = new MediaPlayer(media);
mp.setAutoPlay(true);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
double position = 120;
mp.seek(Duration.seconds(position));
}
});
}
}
MainPane.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<Button fx:id="button" mnemonicParsing="false" text="change position" />
</children>
</AnchorPane>
---------- END SOURCE ----------
SUPPORT :
YES