Music Player

Music Player

3M Downloads

[Question] Where does this mod tell MC/Forge to play the music?

tarbaII opened this issue ยท 4 comments

commented

I have been searching the source code for about 45 minutes now and I can't find where this mod actually tells Minecraft (or Forge) to play the music. I've found the Lavaplayer stuff and the playlist management stuff but I can't find any Minecraft or Forge API calls for the music. Could you point me in the right direction? I'm looking to do something similar in a mod of mine.

commented

Ah that makes sense, thank you very much! How does it stop playing Minecraft's BGM? I don't see anything that might do that there.

commented

The music isn't played through the minecraft sound engine. It's using the javax.sound api here:

try {
final AudioPlayer player = musicPlayer.getAudioPlayer();
final AudioDataFormat dataformat = musicPlayer.getAudioDataFormat();
final AudioInputStream stream = AudioPlayerInputStream.createStream(player, dataformat, dataformat.frameDuration(), false);
final byte[] buffer = new byte[dataformat.chunkSampleCount * dataformat.channelCount * 2];
final long frameDuration = dataformat.frameDuration();
int chunkSize;
while (true) {
if (souceLine == null || !souceLine.isOpen()) {
closeLine();
if (!createLine()) {
sleep(500);
continue;
}
}
if (!player.isPaused()) {
if ((chunkSize = stream.read(buffer)) >= 0) {
souceLine.write(buffer, 0, chunkSize);
if (musicPlayer.getOutputConsumer() != null) {
musicPlayer.getOutputConsumer().accept(Arrays.copyOf(buffer, buffer.length), chunkSize);
}
} else {
throw new IllegalStateException("Audiostream ended. This should not happen.");
}
} else {
souceLine.drain();
sleep(frameDuration);
}
}
} catch (final Exception ex) {
ex.printStackTrace();
}

commented
commented

I appreciate the help :)