Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. // Getting a music file
  2. // By Dan "Floorman" Moody
  3.  
  4. package com.you.package;
  5.  
  6. import java.applet.Applet;
  7. import java.applet.AudioClip;
  8.  
  9. public class Sound {
  10.     // Declare a new AudioClip
  11.     public AudioClip sound;
  12.    
  13.     // Every time you make a new sound file (which must be .wav) you should declare it here.
  14.     public static Sound sound1 = new Sound("/music.wav"); // the slash is needed so it finds the file.
  15.    
  16.     // The Constructor which will require a file to be declared
  17.     public Sound(String file) {
  18.         sound = Applet.newAudioClip(Sound.class.getResource(file)); // this gets the file
  19.     }
  20.    
  21.     // The method that plays the file
  22.     public void play() {
  23.         new Thread() { // You must declare a new thread
  24.             public void run() { // Declare a new run method
  25.                 sound.play(); // This is self explanatory
  26.             }
  27.         }.start(); // Pay attention to this if you're not so hot on Threads
  28.     }
  29. }
Add Comment
Please, Sign In to add comment