1

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!

Nicholas
  • 41
  • 2
  • 6

1 Answers1

2

You could just combine the files into a single file following the method here. Make sure to combine, not concatenate. If one file is longer than the other you can just zero pad until the lengths are equivalent.

It sounds like in the linked post there were equalization or clipping problems. I would normalize (i.e. 1 is maximum .wav value) both files to half of the maximum value (make 0.5 the maximum value) and then simply add each sample together to get a combined audio file guranteed not to clip. Each file has the same volume following this method.

If different sampling rates were used between the files use upsampling/downsampling as appropriate.

thomas.cloud
  • 881
  • 13
  • 30