Class Sound

java.lang.Object
org.openpatch.scratch.internal.Sound

public class Sound extends Object
The Sound class represents a sound object in Scratch. It includes fields for the name of the sound and the sound file.

Example usage:


 Sound s = new Sound("mySound", "path/to/sound.wav");
 s.play();
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sound(String name, String soundPath)
    Creates a new ScratchSound object.
    Copies a ScratchSound object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeVolume(double step)
    Changes the volume by a step
    Returns the name
    double
    Returns the volume
    boolean
    Return true if the sound file is playing.
    void
    Pauses the playing of the sound file.
    void
    Starts playing the sound file.
    void
    setVolume(double amp)
    Sets the volume
    void
    Stops the playing of the sound file.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sound

      public Sound(String name, String soundPath)
      Creates a new ScratchSound object.
      Parameters:
      name - The name of the sound
      soundPath - The path to the sound file
    • Sound

      public Sound(Sound s)
      Copies a ScratchSound object.
      Parameters:
      s - ScratchSound object to copy
  • Method Details

    • getName

      public String getName()
      Returns the name
      Returns:
      the name
    • play

      public void play()
      Starts playing the sound file.
    • pause

      public void pause()
      Pauses the playing of the sound file.
    • stop

      public void stop()
      Stops the playing of the sound file.
    • isPlaying

      public boolean isPlaying()
      Return true if the sound file is playing.
      Returns:
      sound file is playing
    • setVolume

      public void setVolume(double amp)
      Sets the volume
      Parameters:
      amp - A volume [0...1]
    • changeVolume

      public void changeVolume(double step)
      Changes the volume by a step
      Parameters:
      step - The step to change the volume by
    • getVolume

      public double getVolume()
      Returns the volume
      Returns:
      the volume