I'm currently working on a project which is a small educational game for children. Right now I am working on the intro screen and I seem to be having some issues with the sound. Initially I thought that perhaps the mp3 files could have been causing the issue because I had read that it's better to use .wav files instead. The two sounds are a buzzing bee sound, and the opening theme when the game opens. Sometimes it works flawlessly and there aren't any problems, other times the sounds both play for a second and then cut out. If someone could point my in the right direction that would be a great deal of help.
I've tried to convert the files to .wav files, this doesn't really seem to fix the issue. I've tried to define the mediaplayers as properties, to avoid the garbage collection routine which is clearing the instance of the mediaplayer. This also doesn't seem to fix the issue.
public class Intro extends Application{
MediaPlayer mediaPlayer;
MediaPlayer mediaPlayer2;
@Override
public void start(Stage primaryStage) {
// TODO Auto-generated method stub
//THE BEES
String musicFile = "thebees.wav";
String music2 = "opening.wav";
Pane root = new Pane();
Scene scene = new Scene(root, 600, 500);
//Bee sound
Media sound = new Media(new File(musicFile).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound);
mediaPlayer.play();
Media sound2 = new Media(new File(music2).toURI().toString());
MediaPlayer mediaPlayer2 = new MediaPlayer(sound2);
mediaPlayer2.play();
What I'm going for is that when the intro screen is opened that both files will play simultaneously. Thank you again to anyone who helps!