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
 *    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.
Binder for WAV sound files

Aritz Lopez
public class Sound {
    private final Clip clip;

Load a Sound from a URL.

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();
        } 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:
    public void play() {

True iff it is playing.

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:
    public void stop() {

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