Guest User

Untitled

a guest
Jan 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public class PlaySounds {
  2. private AudioInputStream audioStream;
  3. public static Clip clip;
  4. private URL url;
  5. public static int nextSound;
  6.  
  7. public void playAllSounds() {
  8. for (String str : soundList) { // arrayList of sounds
  9. str = soundList.get(nextSound);
  10. url = getClass().getResource(str);
  11. }
  12. try {
  13.  
  14. audioStream = AudioSystem.getAudioInputStream(url);
  15. clip = AudioSystem.getClip();
  16. clip.open(audioStream);
  17. clip.start();
  18.  
  19. } catch (Exception e) {
  20. }
  21.  
  22. }
  23. }
  24.  
  25. PlaySounds ps = new PlaySounds();
  26. int next = 0;
  27. List<Integer> positions = new ArrayList<>();
  28. /*Some other methods....
  29. ....
  30. */
  31. private void getshuffledPositions() {
  32.  
  33. for (int i = 0, i <=12; i++) {
  34. positions.add(i);
  35.  
  36. }
  37. Collections.shuffle(positions);
  38.  
  39. }
  40. public void actionPerformed(ActionEvent ae) {
  41.  
  42. if (ae.getSource() == playButton) {
  43. //Some codes.....Here I tried boolean flag, etc
  44. ps.nextSound = positions.get(next);
  45. ps.playAllSounds();
  46. //Some more codes.....
Add Comment
Please, Sign In to add comment