Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Getting a music file
- // By Dan "Floorman" Moody
- package com.you.package;
- import java.applet.Applet;
- import java.applet.AudioClip;
- public class Sound {
- // Declare a new AudioClip
- public AudioClip sound;
- // Every time you make a new sound file (which must be .wav) you should declare it here.
- public static Sound sound1 = new Sound("/music.wav"); // the slash is needed so it finds the file.
- // The Constructor which will require a file to be declared
- public Sound(String file) {
- sound = Applet.newAudioClip(Sound.class.getResource(file)); // this gets the file
- }
- // The method that plays the file
- public void play() {
- new Thread() { // You must declare a new thread
- public void run() { // Declare a new run method
- sound.play(); // This is self explanatory
- }
- }.start(); // Pay attention to this if you're not so hot on Threads
- }
- }
Add Comment
Please, Sign In to add comment