Thread: [PI] Simple Music/Sound System

Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33
  1. #1 [PI] Simple Music/Sound System 
    Registered Member
    Join Date
    Jan 2013
    Posts
    41
    Thanks given
    2
    Thanks received
    6
    Rep Power
    11
    Hey rune-server this is my first tutorial and its pretty simple to be honest. I am not going to spoonfeed because this is so simple to add. If you can't add it, there is something wrong with you tbh. Well lets get started!

    First make a new class called Music.java and place it in your client folder with all the other files client.java, sprite.java, etc.

    Code:
    import java.io.*;
    import javax.sound.sampled.*;
    import sign.*;
    import java.util.*;
    
    public class Music {
       
       private static Clip clip;
       
       //use to choose a random song
       public static void playRandom() {
    	   Random random = new Random();
    	   int play = random.nextInt(4);
    	   Music("jingle"+play);
       }
       
       //gets file by name and opens audio system
       public static void Music(String soundFileName) {
          String dir = signlink.findcachedir();
          try {
             AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(dir+"/Music/"+soundFileName).getAbsoluteFile());
             clip = AudioSystem.getClip();
             clip.open(audioInputStream);
    		 play();
          } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
          }
       }
       
       //starts playing the actual music
       public static void play() {
             if (clip.isRunning()) {
                  clip.stop();
              }
             clip.setFramePosition(0);
             clip.start();
          }
       
       //stops the music if needed
       public static void stop() {
    	   clip.stop();
    	   clip.setFramePosition(0);
    	   clip.close();
    	  }
    }
    Thats it basically for the music system. Now to play a song all you do is Music.Music(filename);

    Example:

    Download Little bird tune: UPLOAD.EE - Download sound5.wav

    Now create a folder in your cache called "Music" and place that file in there.

    Now open client.java and find "loggedIn = true" and under add it under it

    Code:
    Music.Music("sound5.wav");
    Thanks for reading guys and thank me or rep if you use =)
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Join Date
    May 2013
    Posts
    8
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Actually works, give us more usage though
    Reply With Quote  
     

  4. #3  
    Registered Member
    Join Date
    Jul 2009
    Age
    28
    Posts
    537
    Thanks given
    20
    Thanks received
    3
    Rep Power
    8
    Wrong section
    Nice post, but post in client tuts.


    #100 Posts - #200 Posts - #300 Posts - #400 Posts - #500 Posts -
    #600 Posts - #700 Posts - #800 Posts #900 Posts - #1000 Posts
    Reply With Quote  
     

  5. #4  
    Registered Member
    Join Date
    Jan 2013
    Posts
    41
    Thanks given
    2
    Thanks received
    6
    Rep Power
    11
    Quote Originally Posted by nl pk3er View Post
    Wrong section
    Nice post, but post in client tuts.
    crap I just realized that. I was looking though the show-off section and got bored and thought i would release this. Forgot to change section lol.
    Reply With Quote  
     

  6. #5  
    Registered Member

    Join Date
    May 2012
    Age
    28
    Posts
    1,548
    Thanks given
    415
    Thanks received
    231
    Rep Power
    81
    Quote Originally Posted by FuzzyAvacado View Post
    Hey rune-server this is my first tutorial and its pretty simple to be honest. I am not going to spoonfeed because this is so simple to add. If you can't add it, there is something wrong with you tbh. Well lets get started!

    First make a new class called Music.java and place it in your client folder with all the other files client.java, sprite.java, etc.

    Code:
    import java.io.*;
    import javax.sound.sampled.*;
    import sign.*;
    import java.util.*;
    
    public class Music {
       
       private static Clip clip;
       
       //use to choose a random song
       public static void playRandom() {
    	   Random random = new Random();
    	   int play = random.nextInt(4);
    	   Music("jingle"+play);
       }
       
       //gets file by name and opens audio system
       public static void Music(String soundFileName) {
          String dir = signlink.findcachedir();
          try {
             AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(dir+"/Music/"+soundFileName).getAbsoluteFile());
             clip = AudioSystem.getClip();
             clip.open(audioInputStream);
    		 play();
          } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
          }
       }
       
       //starts playing the actual music
       public static void play() {
             if (clip.isRunning()) {
                  clip.stop();
              }
             clip.setFramePosition(0);
             clip.start();
          }
       
       //stops the music if needed
       public static void stop() {
    	   clip.stop();
    	   clip.setFramePosition(0);
    	   clip.close();
    	  }
    }
    Thats it basically for the music system. Now to play a song all you do is Music.Music(filename);

    Example:

    Download Little bird tune: UPLOAD.EE - Download sound5.wav

    Now create a folder in your cache called "Music" and place that file in there.

    Now open client.java and find "loggedIn = true" and under add it under it

    Code:
    Music.Music("sound5.wav");
    Thanks for reading guys and thank me or rep if you use =)
    Nice. will test later.
    Inactive.


    Spoiler for FirstDesign:
    Reply With Quote  
     

  7. #6  
    Extreme Donator
    cia nick's Avatar
    Join Date
    Oct 2011
    Posts
    92
    Thanks given
    21
    Thanks received
    6
    Rep Power
    0
    Looking forward to trying this out maybe we can implement regions into this!
    Reply With Quote  
     

  8. #7  
    Extreme Donator
    cia nick's Avatar
    Join Date
    Oct 2011
    Posts
    92
    Thanks given
    21
    Thanks received
    6
    Rep Power
    0
    Quote Originally Posted by FuzzyAvacado View Post
    Hey rune-server this is my first tutorial and its pretty simple to be honest. I am not going to spoonfeed because this is so simple to add. If you can't add it, there is something wrong with you tbh. Well lets get started!

    First make a new class called Music.java and place it in your client folder with all the other files client.java, sprite.java, etc.

    Code:
    import java.io.*;
    import javax.sound.sampled.*;
    import sign.*;
    import java.util.*;
    
    public class Music {
       
       private static Clip clip;
       
       //use to choose a random song
       public static void playRandom() {
    	   Random random = new Random();
    	   int play = random.nextInt(4);
    	   Music("jingle"+play);
       }
       
       //gets file by name and opens audio system
       public static void Music(String soundFileName) {
          String dir = signlink.findcachedir();
          try {
             AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(dir+"/Music/"+soundFileName).getAbsoluteFile());
             clip = AudioSystem.getClip();
             clip.open(audioInputStream);
    		 play();
          } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
          }
       }
       
       //starts playing the actual music
       public static void play() {
             if (clip.isRunning()) {
                  clip.stop();
              }
             clip.setFramePosition(0);
             clip.start();
          }
       
       //stops the music if needed
       public static void stop() {
    	   clip.stop();
    	   clip.setFramePosition(0);
    	   clip.close();
    	  }
    }
    Thats it basically for the music system. Now to play a song all you do is Music.Music(filename);

    Example:

    Download Little bird tune: UPLOAD.EE - Download sound5.wav

    Now create a folder in your cache called "Music" and place that file in there.

    Now open client.java and find "loggedIn = true" and under add it under it

    Code:
    Music.Music("sound5.wav");
    Thanks for reading guys and thank me or rep if you use =)
    Ok, this is great but we need volume adjustment I'm not quite sure how to do this but... I will look into it...
    Reply With Quote  
     

  9. #8  
    Extreme Donator
    cia nick's Avatar
    Join Date
    Oct 2011
    Posts
    92
    Thanks given
    21
    Thanks received
    6
    Rep Power
    0
    Quote Originally Posted by Logic View Post
    It works, I just don't see what's there you could do with it really. Gj tho
    There is much you can do with this... I have many ideas i just need to know how to add this to the volume adjust option any ideas?
    Reply With Quote  
     

  10. #9  
    Banned
    Join Date
    May 2013
    Age
    22
    Posts
    557
    Thanks given
    35
    Thanks received
    45
    Rep Power
    0
    Amazing work man
    Reply With Quote  
     

  11. #10  
    Banned
    Join Date
    May 2013
    Posts
    497
    Thanks given
    31
    Thanks received
    3
    Rep Power
    0
    I'm going to add whip sound, and food sound, etcc, how ?

    Just tell me how to add whip sound, and I'll add more soon )

    Repp+
    Reply With Quote  
     

Page 1 of 4 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Basic Combat sound system
    By $nitro$ in forum Tutorials
    Replies: 64
    Last Post: 01-28-2016, 04:34 PM
  2. [PI] Simple News Feed System
    By I'm A Jerk in forum Tutorials
    Replies: 9
    Last Post: 08-16-2012, 06:23 AM
  3. Buying Music/Sound effect system [PI]
    By Anc13nts in forum Buying
    Replies: 0
    Last Post: 09-26-2011, 08:18 AM
  4. [459] Music & Sounds + System
    By Vault in forum Buying
    Replies: 5
    Last Post: 07-09-2011, 01:16 PM
  5. Simple weapon sound system
    By Aeterna in forum Snippets
    Replies: 4
    Last Post: 11-02-2009, 09:56 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •