Module hanyaeger

Class SoundClip

java.lang.Object
com.github.hanyaeger.api.media.SoundClip

public class SoundClip extends Object
A SoundClip encapsulates a mp3 audio file. This file can be played once, or looped for a given amount of times, or indefinite. The path of the mp3 file should be passed to the constructor and the file should be available on the class path.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    When instantiating a SoundClip, the value of the constructor parameter cycleCount can be used to set the number of times the audio file should be played.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate a new SoundClip for the given file, which should be played only once.
    SoundClip(String path, int cycleCount)
    Instantiate a new SoundClip for the given file, which should be played for the given amount provided of cycleCount.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Get the default volume level.
    void
    Play the file.
    void
    setVolume(double volume)
    Set the default volume level.
    void
    Stop playing the file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INDEFINITE

      public static final int INDEFINITE
      When instantiating a SoundClip, the value of the constructor parameter cycleCount can be used to set the number of times the audio file should be played. When the constant {#link #INDEFINITE} is used, the file be played in ann infinite loop.
      See Also:
  • Constructor Details

    • SoundClip

      public SoundClip(String path)
      Instantiate a new SoundClip for the given file, which should be played only once.
      Parameters:
      path - the path of the mp3 file. Note that this font file should be available on the Class Path and should be opened through the module descriptor.
    • SoundClip

      public SoundClip(String path, int cycleCount)
      Instantiate a new SoundClip for the given file, which should be played for the given amount provided of cycleCount.
      Parameters:
      path - the path of the mp3 file. Note that this font file should be available on the Class Path and should be opened through the module descriptor.
      cycleCount - the number of times the audio file should be played. To loop a file indefinitely, use a cycleCount of INDEFINITE
  • Method Details

    • play

      public void play()
      Play the file. It will be played for the given cycleCount, which is 1 by default. If the file should be looped indefinably, the cycleCount should be set to the constant value INDEFINITE.
    • stop

      public void stop()
      Stop playing the file.
    • setVolume

      public void setVolume(double volume)
      Set the default volume level. The new setting will only take effect on subsequent plays.
      Parameters:
      volume - new default volume level for this clip
    • getVolume

      public double getVolume()
      Get the default volume level.
      Returns:
      the default volume level for this clip