dockyard-nbs is a dockyardmc library that implements the NBS file format and allows for playing noteblock songs in-game
repositories {
maven {
name = "devOS"
url = uri("https://mvn.devos.one/releases")
}
}
dependencies {
implementation("io.github.dockyardmc:dockyard-nbs:1.0")
}You can parse the nbs file either using NBSFile.fromFile(file) or NBSReader.read(file). You then get a NBSTrack class and you can then add a "listener" to it and use the start() method to play it
val track = NBSReader.read(File("./nbs/bad_apple.nbs"))
track.listeners.add(player)
track.start()You can change the volume by either:
- Setting the
volumefield manually - Using
fadeTo(volume, time),fadeFromZero(time),fadeToZero(time)functions which interpolate the volume over time
You can control the playback of the track by using:
stop()to stop the playbackstart()to start/resume playbackseek(time)to skipreset()to stop the track and reset it to initial statedispose()to get dispose the track and the timer
You can also change the looping field to enable/disable automatic looping