Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.atm959.sourceCode;
- 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.DataLine;
- import javax.sound.sampled.LineUnavailableException;
- import javax.sound.sampled.UnsupportedAudioFileException;
- public class Sounds {
- File soundFileBgm;
- File soundFileSfx;
- AudioInputStream soundBgm;
- AudioInputStream soundSfx;
- DataLine.Info infoBgm;
- DataLine.Info infoSfx;
- Clip clipBgm;
- Clip clipSfx;
- @SuppressWarnings("static-access")
- public void startBgm(String fileName) throws UnsupportedAudioFileException, IOException, LineUnavailableException{
- soundFileBgm = new File("bgm/" + fileName);
- soundBgm = AudioSystem.getAudioInputStream(soundFileBgm);
- infoBgm = new DataLine.Info(Clip.class, soundBgm.getFormat());
- clipBgm = (Clip) AudioSystem.getLine(infoBgm);
- clipBgm.open(soundBgm);
- clipBgm.start();
- clipBgm.loop(clipBgm.LOOP_CONTINUOUSLY);
- }
- public void stopBgm(){
- clipBgm.stop();
- clipBgm.close();
- }
- public void pauseBgm(){
- clipBgm.stop();
- }
- public void resumeBgm(){
- clipBgm.start();
- }
- public void playSfx(String fileName) throws UnsupportedAudioFileException, IOException, LineUnavailableException{
- soundFileSfx = new File("sfx/" + fileName);
- soundSfx = AudioSystem.getAudioInputStream(soundFileSfx);
- infoSfx = new DataLine.Info(Clip.class, soundSfx.getFormat());
- clipSfx = (Clip) AudioSystem.getLine(infoSfx);
- clipSfx.open(soundSfx);
- clipSfx.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment