diff options
author | Zach Jordan <zxjordan5@gmail.com> | 2023-06-05 08:38:00 -0400 |
---|---|---|
committer | Zach Jordan <zxjordan5@gmail.com> | 2023-06-05 08:38:00 -0400 |
commit | b6826c6ba281366efc60e89d73d3b6f81d4f2b80 (patch) | |
tree | 4d4dc505eb71cd0306fc07b44928eec3f152572c /src/sound/AudioFilePlayer.java | |
parent | 649bb51ed3d7a55fd136b511a96e008298db5c7b (diff) | |
parent | fc23e12aa682298a6845d0085f1d39dae1d9c5b6 (diff) | |
download | NPEhero-b6826c6ba281366efc60e89d73d3b6f81d4f2b80.tar.gz NPEhero-b6826c6ba281366efc60e89d73d3b6f81d4f2b80.tar.bz2 NPEhero-b6826c6ba281366efc60e89d73d3b6f81d4f2b80.zip |
Merge branch 'main' of https://gitlab.sowgro.net/guitarheros/guitarhero
Diffstat (limited to 'src/sound/AudioFilePlayer.java')
-rw-r--r-- | src/sound/AudioFilePlayer.java | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/src/sound/AudioFilePlayer.java b/src/sound/AudioFilePlayer.java deleted file mode 100644 index 9425881..0000000 --- a/src/sound/AudioFilePlayer.java +++ /dev/null @@ -1,148 +0,0 @@ -package sound; - -import java.io.File; -import java.io.IOException; -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Clip; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; - -//Java program to play audio files. imports file scanning and various -//methods from the java audio class in order to do so. -public class AudioFilePlayer -{ - - // to store current position - Long currentFrame; - Clip clip; - - // current status of clip - String status; - - AudioInputStream audioInputStream; - private String filePath; - - File audioFile; - // constructor to initialize streams and clip - public AudioFilePlayer(String newFilePath) - { - filePath = newFilePath; - audioFile = new File(filePath); - // create AudioInputStream object - try { - audioInputStream = AudioSystem.getAudioInputStream(new File(filePath).getAbsoluteFile()); - } - catch (UnsupportedAudioFileException e) { - e.printStackTrace(); - } - catch (IOException e) { - e.printStackTrace(); - } - - // create clip reference - try { - clip = AudioSystem.getClip(); - } - catch (LineUnavailableException e) { - e.printStackTrace(); - } - - // open audioInputStream to the clip - try { - clip.open(audioInputStream); - } - catch (LineUnavailableException e) { - e.printStackTrace(); - } - catch (IOException e) { - e.printStackTrace(); - } - - - } - - // Method to play the audio - public void play() - { - //start the clip - clip.start(); - - status = "play"; - } - - // Method to pause the audio - public void pause() - { - if (status.equals("paused")) - { - System.out.println("audio is already paused"); - return; - } - this.currentFrame = this.clip.getMicrosecondPosition(); - clip.stop(); - status = "paused"; - } - - // Method to resume the audio - public void resumeAudio() throws UnsupportedAudioFileException, - IOException, LineUnavailableException - { - if (status.equals("play")) - { - System.out.println("Audio is already "+ - "being played"); - return; - } - clip.close(); - resetAudioStream(); - clip.setMicrosecondPosition(currentFrame); - this.play(); - } - - // Method to restart the audio - public void restart() throws IOException, LineUnavailableException, - UnsupportedAudioFileException - { - clip.stop(); - clip.close(); - resetAudioStream(); - currentFrame = 0L; - clip.setMicrosecondPosition(0); - this.play(); - } - - // Method to stop the audio - public void stop() throws UnsupportedAudioFileException, - IOException, LineUnavailableException - { - currentFrame = 0L; - clip.stop(); - clip.close(); - } - - // Method to jump over a specific part - public void jump(long c) throws UnsupportedAudioFileException, IOException, - LineUnavailableException - { - if (c > 0 && c < clip.getMicrosecondLength()) - { - clip.stop(); - clip.close(); - resetAudioStream(); - currentFrame = c; - clip.setMicrosecondPosition(c); - this.play(); - } - } - - // Method to reset audio stream - public void resetAudioStream() throws UnsupportedAudioFileException, IOException, LineUnavailableException - { - audioInputStream = AudioSystem.getAudioInputStream( - new File(filePath).getAbsoluteFile()); - clip.open(audioInputStream); - clip.loop(Clip.LOOP_CONTINUOUSLY); - } - -}
\ No newline at end of file |