Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test.sound;
- import javax.sound.sampled.AudioInputStream;
- import javax.sound.sampled.AudioSystem;
- import javax.sound.sampled.Clip;
- public class main {
- public static void main(String[] args) {
- }
- public static synchronized void playSound(final String url) {
- new Thread(new Runnable() {
- // The wrapper thread is unnecessary, unless it blocks on the
- // Clip finishing; see comments.
- public void run() {
- try {
- Clip clip = AudioSystem.getClip();
- AudioInputStream inputStream = AudioSystem.getAudioInputStream(
- main.class.getResourceAsStream("/sound/test.wav/" + url));
- clip.open(inputStream);
- clip.start();
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
- }).start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement