Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Stop a Sound from Playing in a PlaySoundEvent #1778

Closed
masl123 opened this issue Apr 9, 2015 · 8 comments
Closed

Can't Stop a Sound from Playing in a PlaySoundEvent #1778

masl123 opened this issue Apr 9, 2015 · 8 comments
Labels
Bug This request reports or fixes a new or existing bug.

Comments

@masl123
Copy link

masl123 commented Apr 9, 2015

HI,
I'm currently working on a mp3 Player Mod, and so I have to Stop any Background Music from playing when the Player is playing music. I have tried to Subscribe to the PlaySoundEvent to stop the Music. But I cant stop the Music from Playing. I have tried these three Methods:

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void PlaySoundEvent (PlaySoundEvent event){
     System.out.println("Played Streamed Sound:  "+event.category);
     if(event.category == SoundCategory.MUSIC){
                //1.
        event.manager.stopSound(event.sound); //no sound has been played yet
                //2.
        event.setResult(null); //this should Work
                //3.
        event.setCanceled(true); //Crashes the Game
    }
}

I'm using Forge 11.14.1299 (I know that this isn't the newest Version of Forge, but I have had a look in the Changelog and there were no issues regarding that).

In Minecraft 1.7 (Forge V1.7.10-10.13.0.1180) this Worked:

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void PlaySoundEvent(PlaySoundEvent17 event){
        event.manager.sndHandler.stopSound(event.sound);
        event.result = null;
}

BTW:
Is there a way of playing a File from a specified Path and not use the SoundSystem directly, or get the SoundSystem Object without reflection?

@LexManos
Copy link
Member

LexManos commented Apr 9, 2015

Logs.

@masl123
Copy link
Author

masl123 commented Apr 9, 2015

What do you mean, by saying Logs? Do you want any Logs from me? There are no important Logs, because its a semantic Bug, a Bug, which does not throw any Exceptions, except for the last one, becuase the Event is not cancelable.

@GotoLink
Copy link
Contributor

GotoLink commented Apr 9, 2015

PlaySoundEvent does not have HasResult or Cancellable annotations.
Thus neither Event#setCancelled(boolean) not Event#setResult(Result) would work.
You should edit the PlaySoundEvent#result field, exactly like in 1.7.

@ShetiPhian
Copy link
Contributor

Why each doesn't work.
event.manager.stopSound(event.sound); Just as you pointed out, the sound hasn't started.
event.setCanceled(true); the event is not flagged Cancelable
event.setResult(null); this is expecting the enum Result (DENY, DEFAULT, ALLOW)

The old way you used in 1.7 should be what your after. event.result = null;

EDIT:
@GotoLink you ninja, sneaking in there a few seconds before me ;)

@masl123
Copy link
Author

masl123 commented Apr 9, 2015

Thanks, for your Help. Although, its confusing, naming a Function getResult and setResult?? You could rename them to setResultState and getResultState, just to clarify things. Because right now, it looks like you would set the event.result.

@masl123
Copy link
Author

masl123 commented Apr 9, 2015

OK, but if I try now to stop the music by using soundHandler.stopSound() (I want to Stop the music if the user clicks on the Play Button of the GUi), if a GUI is Open, and I Close the GUI again, the Music starts to Play again from the beginning on, without generating an Event. (I Think its the same situation when you open and close the Esc Menu). Only Calling the Method again and the soundHandler.update() Method, after the GUI has been Closed helps.

This did not happen in MC 1.7.

@Actuarius
Copy link

@diesieben07 added labels [Bug]

@Actuarius Actuarius added the Bug This request reports or fixes a new or existing bug. label May 25, 2016
@LexManos
Copy link
Member

setResultSound(null) will prevent the sound from playing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This request reports or fixes a new or existing bug.
Projects
None yet
Development

No branches or pull requests

5 participants