java.lang.Object
de.pirckheimer_gymnasium.engine_pi.sound.Jukebox

public final class Jukebox extends Object
Die Jukebox Klasse bietet Methoden an, um Klänge und Musik im Spiel wiederzugeben.

Die Jukebox kann standardmäßig .wav, .mp3 und .ogg Dateien abspielen. Wenn Sie andere Dateierweiterungen benötigen, müssen Sie eine eigene SPI-Implementierung schreiben und sie in Ihr Projekt einbauen.

  • Field Details

  • Constructor Details

    • Jukebox

      public Jukebox()
  • Method Details

    • getMaxDistance

      public int getMaxDistance()
      Gets the maximum distance from the listener at which a sound source can still be heard.
      Returns:
      The maximum distance at which a sound can be heard.
    • playMusic

      public MusicPlayback playMusic(Sound music)
      Sets the currently playing track to a LoopedTrack with the specified music Sound. This has no effect if the specified track is already playing.
      Parameters:
      music - The Sound to be played.
      Returns:
      The playback of the music
    • playMusic

      public MusicPlayback playMusic(Track track)
      Sets the currently playing track to the specified track. This has no effect if the specified track is already playing.
      Parameters:
      track - The track to play
      Returns:
      The playback of the music
    • playMusic

      public MusicPlayback playMusic(Track track, boolean restart)
      Sets the currently playing track to the specified track.
      Parameters:
      track - The track to play
      restart - Whether to restart if the specified track is already playing, determined by Object.equals(Object)
      Returns:
      The playback of the music
    • playMusic

      public MusicPlayback playMusic(Track track, boolean restart, boolean stop)
      Plays the specified track.
      Parameters:
      track - The track to play
      restart - Whether to restart if the specified track is already playing, determined by Object.equals(Object)
      stop - Whether to stop an existing track if present
      Returns:
      The playback of the music
    • playMusic

      public MusicPlayback playMusic(Track track, Consumer<? super MusicPlayback> config, boolean restart, boolean stop)
      Plays the specified track, optionally configuring it before starting.
      Parameters:
      track - The track to play
      config - A call to configure the playback prior to starting, which can be null
      restart - Whether to restart if the specified track is already playing, determined by Object.equals(Object)
      stop - Whether to stop an existing track if present
      Returns:
      The playback of the music
    • getMusic

      public MusicPlayback getMusic()
      Gets the "main" music that is playing. This usually means the last call to playMusic, though if the music has been stopped it will be null.
      Returns:
      The main music, which could be null.
    • getAllMusic

      public Collection<MusicPlayback> getAllMusic()
      Liefert eine Liste mit allen Musikwiedergaben.
      Returns:
      Eine Liste mit allen Musikwiedergaben.
    • setMaxDistance

      public void setMaxDistance(int radius)
      Sets the default maximum distance from the listener at which a sound source can still be heard. If the distance between the sound source and the listener is greater than the specified value, the volume is set to 0.
      Parameters:
      radius - The maximum distance at which sounds can still be heard.
    • stopMusic

      public void stopMusic()
      Stoppt die Wiedergabe der aktuellen Hintergrundmusik.
    • getSound

      public Sound getSound(String filePath)
    • createPlayback

      public SoundPlayback createPlayback(Sound sound, boolean loop)
      Creates an SoundPlayback object that can be configured prior to starting.

      Unlike the playSound methods, the SoundPlayback objects returned by this method must be started using the Playback.start() method. However, necessary resources are acquired immediately upon calling this method, and will remain in use until the playback is either cancelled or finalized.

      Parameters:
      sound - The sound to play
      loop - Whether to loop the sound
      Returns:
      An SoundPlayback object that can be configured prior to starting, but will need to be manually started.
    • createPlayback

      public SoundPlayback createPlayback(String filePath, boolean loop)
    • playSound

      public SoundPlayback playSound(Sound sound, boolean loop)
    • playSound

      public SoundPlayback playSound(String filePath, boolean loop)
    • playSound

      public SoundPlayback playSound(String filePath)