-
Notifications
You must be signed in to change notification settings - Fork 54
Playing songs
koca2000 edited this page Feb 15, 2021
·
6 revisions
Song in .nbs format have to be loaded before you can use it. Since 1.2.2 you can add multiple Song to Playlist, so they will be automatically played one after another.
Song song = NBSDecoder.parse(new File("path/to/file"));
Song song2 = NBSDecoder.parse(new File("path/to/another/file"));
Playlist playlist = new Playlist(song, song2,...);
There are 4 types of SongPlayer:
Play song for all added players no matter where they are.
Song song; // Preloaded song
// Create RadioSongPlayer.
RadioSongPlayer rsp = new RadioSongPlayer(song);
// Add player to SongPlayer so he will hear the song.
rsp.addPlayer(Player);
// Start RadioSongPlayer playback
rsp.setPlaying(true);
Play song for all added players in specified range from specified point.
Song song; // Preloaded song
// Create PositionSongPlayer.
PositionSongPlayer psp = new PositionSongPlayer(song);
// Set location where the song will be playing
psp.setTargetLocation(Location);
// Set distance from target location in which will players hear the SongPlayer
psp.setDistance(16); // Default: 16
// Add player to SongPlayer so he will hear the song.
psp.addPlayer(Player);
// Start RadioSongPlayer playback
psp.setPlaying(true);
Play song for all added players in specified range from specified NoteBlock Block.
Song song; // Preloaded song
// Create NoteBlockSongPlayer.
NoteBlockSongPlayer nbsp = new NoteBlockSongPlayer(song);
// Set block where the song will be playing
nbsp.setNoteBlock(Block);
// Set distance from target location in which will players hear the SongPlayer
nbsp.setDistance(16); // Default: 16
// Add player to SongPlayer so he will hear the song.
nbsp.addPlayer(Player);
// Start RadioSongPlayer playback
nbsp.setPlaying(true);
Play song for all added players in specified range from specified entity.
Song song; // Preloaded song
// Create EntitySongPlayer.
EntitySongPlayer esp = new EntitySongPlayer(song);
// Set entity which position will be used
esp.setEntity(Entity);
// Set distance from target location in which will players hear the SongPlayer
esp.setDistance(16); // Default: 16
// Add player to SongPlayer so he will hear the song.
esp.addPlayer(Player);
// Start RadioSongPlayer playback
esp.setPlaying(true);