Class SoundManager


  • public class SoundManager
    extends java.lang.Object
    Manages all sounds. Each sound has a sound type (Sounds) attached. Sound types can be disabled (by the user) or muted (by the application). A sound is played only if it is neither disabled nor muted.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void playClip​(@NotNull Sounds type, @Nullable java.lang.String name, @NotNull java.lang.String action)
      Plays a sound clip.
      void playMusic​(@Nullable java.lang.String name)
      Plays a background music.
      void setEffectsEnabled​(boolean enabled)
      Sets whether sound effects are enabled.
      void setMusicEnabled​(boolean enabled)
      Sets whether background music is enabled.
      void shutdown()
      Terminates all sounds and free resources.
      void start()
      Activates this instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SoundManager

        public SoundManager​(@NotNull
                            @NotNull GuiStateManager guiStateManager,
                            @Nullable
                            @Nullable DebugWriter debugSound)
        Creates a new instance.
        Parameters:
        guiStateManager - the gui state manager to watch
        debugSound - the writer for logging sound related information or null to not log
    • Method Detail

      • start

        public void start()
        Activates this instance.
      • setMusicEnabled

        public void setMusicEnabled​(boolean enabled)
        Sets whether background music is enabled.
        Parameters:
        enabled - whether background music is enabled
      • setEffectsEnabled

        public void setEffectsEnabled​(boolean enabled)
        Sets whether sound effects are enabled.
        Parameters:
        enabled - whether sound effects are enabled
      • playClip

        public void playClip​(@NotNull
                             @NotNull Sounds type,
                             @Nullable
                             @Nullable java.lang.String name,
                             @NotNull
                             @NotNull java.lang.String action)
        Plays a sound clip.
        Parameters:
        type - the sound type
        name - an optional prefix for the action name
        action - the sound action name
      • playMusic

        public void playMusic​(@Nullable
                              @Nullable java.lang.String name)
        Plays a background music. If the new music name is unchanged, continue playing.
        Parameters:
        name - the music name
      • shutdown

        public void shutdown()
                      throws java.lang.InterruptedException
        Terminates all sounds and free resources.
        Throws:
        java.lang.InterruptedException - if the current thread was interrupted while waiting for the shutdown