JavaFX MediaPlayer playing background music loop with small intro music

落花浮王杯 提交于 2019-12-25 09:11:03

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/41074777/javafx-mediaplayer-playing-background-music-loop-with-small-intro-music

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!