Scratch for Java

Stage::playSound()

Plays a sound.

Examples

import org.openpatch.scratch.*;
 
public class StagePlaySound {
 
  public StagePlaySound() {
    Stage myStage = new Stage(600, 240);
    myStage.addSound("bump", "assets/bump.wav");
 
    while (myStage.getTimer().forMillis(3000)) {
      myStage.playSound("bump");
      myStage.wait(500);
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new StagePlaySound();
  }
}
 

View on GitHub

Syntax

Java

.playSound(name)

Scratch

play sound (name) until done

Parameters

Name Data Type Description
name String The name of the sound to play

Return

void

playSound()