0

I am trying to create a game using JavaFX. I had been trying to insert some background musics to the game. The musics are of compatible .mp3 files. I am currently using MediaPlayer to playback each Media. Each media file consist of the actual loop and a small (optional) intro music to the loop. How can I achieve smooth audio playback using JavaFX.

Methods I have tried:

  • Using the Media as one file; I try to alter the mediaPlayer.startTime, mediaPlayer.stopTime. It seems that the duration of the music is shortened when I enter the loop. However, the music restarts at the intro and ends at the wrong place. It was as if startTime didn't offset the music at all.

  • Using the Media as two separate files (intro and loop); I try to immediately playback the loop music as soon as the intro music is finished (using mediaPlayer.setOnEndOfMedia()). However, the transition was too slow and noticable.

krismath
  • 1,879
  • 2
  • 23
  • 41
  • Why don't you want to use the event "onEndOfMediaProperty()"? When the song hits the end, you get a notification and can start the next track. – keil Dec 11 '16 at 11:40
  • It was too slow; the skip was very audible. There wasn't an problem with the media itself, I checked. – krismath Dec 11 '16 at 16:35

1 Answers1

0

After experience with other well-known game engines (e.g. Unity), I found that the files should be in .wav format as opposed to .mp3 format. This will allow the music to be looped seamlessly.

krismath
  • 1,879
  • 2
  • 23
  • 41