koca2000 / NoteBlockAPI

https://www.spigotmc.org/resources/noteblockapi.19287/
GNU Lesser General Public License v3.0
120 stars 40 forks source link

how to stop playing noteblock songs? #43

Closed axobeast2020 closed 4 years ago

axobeast2020 commented 4 years ago

I know, how can i start playing noteblocks song, but how stop this Sony? Help me, please.

koca2000 commented 4 years ago

Use songPlayer.setPlaying(false);

axobeast2020 commented 4 years ago

It`s not work

koca2000 commented 4 years ago

Could you be more specific? This code stops the SongPlayer from playing.

axobeast2020 commented 4 years ago

Im sorry for long waiting. I have this code: Song song = NBSDecoder.parse(new File(musicmaster.getDataFolder()+File.separator+"AKindofMagic.nbs")); Playlist playlist = new Playlist(song); RadioSongPlayer rsp = new RadioSongPlayer(playlist); // Add player to SongPlayer so he will hear the song. rsp.addPlayer((Player) sender); String name = rsp.getSong().getTitle(); // Start RadioSongPlayer playback rsp.setPlaying(enabled);, where enabled - is boolean variable. When I want to stop song, I set value of the "enabled" to "false" in "/stop" command, but its not work, song play.

axobeast2020 commented 4 years ago

OOPS! Code: Song song = NBSDecoder.parse(new File(musicmaster.getDataFolder()+File.separator+"AKindofMagic.nbs")); Playlist playlist = new Playlist(song); RadioSongPlayer rsp = new RadioSongPlayer(playlist); // Add player to SongPlayer so he will hear the song. rsp.addPlayer((Player) sender); String name = rsp.getSong().getTitle(); // Start RadioSongPlayer playback rsp.setPlaying(enabled);

koca2000 commented 4 years ago

It doesn't matter whether you use variable or boolean directly in rsp.setPlaying(boolean). You still have to call it again. Add rsp.setPlaying(false); to your /stop command.

axobeast2020 commented 4 years ago

I've been trying to solve the problem with "stop song" for the past few days. I'm trying anyway: ``` public class rounds{

     Song song = NBSDecoder.parse(new File(musicmaster.getDataFolder()+File.separator+"AKindofMagic.nbs"));
     Playlist playlist = new Playlist(song);

     public void starting(Player sender) {
         RadioSongPlayer rsp = new RadioSongPlayer(playlist);
         rsp.addPlayer(sender);
        rsp.setPlaying(true);

     }
     public void stop(Player sender) {
         RadioSongPlayer rsp = new RadioSongPlayer(playlist);

             rsp.setPlaying(false);
         }

}

I'm trying anyway: `public class rounds{

     Song song = NBSDecoder.parse(new File(musicmaster.getDataFolder()+File.separator+"AKindofMagic.nbs"));
     Playlist playlist = new Playlist(song);
     RadioSongPlayer rsp = new RadioSongPlayer(playlist);
     public void starting(Player sender) {

         rsp.addPlayer(sender);
        rsp.setPlaying(true);

     }
     public void stop(Player sender) {

             rsp.setPlaying(false);
         }

}

I'm trying anyway:public class rounds{

     public void starting(Player sender) {
         Song song = NBSDecoder.parse(new File(musicmaster.getDataFolder()+File.separator+"AKindofMagic.nbs"));
         Playlist playlist = new Playlist(song);
         RadioSongPlayer rsp = new RadioSongPlayer(playlist);
         rsp.addPlayer(sender);
        rsp.setPlaying(true);

     }
     public void stop(Player sender) {
         Song song = NBSDecoder.parse(new File(musicmaster.getDataFolder()+File.separator+"AKindofMagic.nbs"));
         Playlist playlist = new Playlist(song);
         RadioSongPlayer rsp = new RadioSongPlayer(playlist);
            rsp.removePlayer(sender);
            rsp.destroy();
             rsp.setPlaying(false);
         }

}`

Аnd many more different options Nothing works, the melody just doesn't turn off. help, can you offer an example of the code that allows you to turn off the ringtone?

axobeast2020 commented 4 years ago

I'm just crying because I can't turn off this stupid tune

koca2000 commented 4 years ago

The second way you sent me is the only one of these three which may work. Do you have Discord? If so please send me a message there. I would me able to help you more interactively. My id is koca2000#6469. It seems like you don't really understand how object in Java works.

axobeast2020 commented 4 years ago

Yes, I'm really new to java. But, I'm sorry i don't have discord.

koca2000 commented 4 years ago

Nevermind. You are creating an object of type RadioSongPlayer. Imagine that it is physical radio on your desk. Every time you call new RadioSongPlayer() it is like when you buy a brand new radio from shop. Now if you turn on one radio and then you want to turn it off, you have to turn off the same piece of radio that you turned on before. It is absolutely same with objects in java. When you want to turn off the radio, you have to have it stored in some variable from the time you turned it on and call the setPlaying method on the same object.

axobeast2020 commented 4 years ago

Yes, I managed to stop the song. Thank you very much! The topic can be closed!