Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2014 Aritz Lopez
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
  *    You may obtain a copy of the License at
  *
  *        http://www.apache.org/licenses/LICENSE-2.0
  *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package io.github.aritzhack.aritzh.awt.audio;
Binder for WAV sound files

Author(s):
Aritz Lopez
public class Sound {
    private final Clip clip;

    
Load a Sound from a URL.

Parameters:
url The URL from which the sound will be loaded.
    public Sound(URL url) {
        Preconditions.checkArgument(url != null"Audio Stream cannot be null!");
        try {
            this. = AudioSystem.getClip();
            this..open(AudioSystem.getAudioInputStream(url));
        } catch (UnsupportedAudioFileException | LineUnavailableException | IOException e) {
            throw new IllegalArgumentException("Could not load sound!"e);
        }
    }

    
Start playing the sound. Note: Starts from the beginning each time. In order to keep playing from where it stopped, use keepGoing().

See also:
keepGoing()
    public void play() {
        this..setMicrosecondPosition(0);
        this..start();
    }

    
True iff it is playing.

Returns:
true if it is playing.
    public boolean isPlaying() {
        return this..isRunning();
    }

    
Stops playing the sound. Will keep the position so that the playback can be continued with keepGoing().

See also:
keepGoing()
    public void stop() {
        this..stop();
    }

    
Plays the sound from where it was stopped, or from the beginning if it was just loaded.
    public void keepGoing() {
        this..start();
    }
New to GrepCode? Check out our FAQ X