Thread: Music Command

Results 1 to 6 of 6
  1. #1 Music Command 
    Registered Member
    Wage's Avatar
    Join Date
    Mar 2014
    Posts
    58
    Thanks given
    33
    Thanks received
    14
    Rep Power
    97
    This thread is rather pointless, you may or may not catch a disease from this post. *Disclaimer

    I'm new to Java and I had an idea the other day for a command that would play a custom sound track that lets say, I had in a specific folder. Like I said pointless but
    I just wanted to know if this was even possible, what format the song would required to be in, and how I would do it. I'm not expecting anyone to spoonfeed me.
    Reply With Quote  
     

  2. #2  
    Stand guard at the door of your mind

    Proto's Avatar
    Join Date
    Jul 2011
    Age
    29
    Posts
    1,234
    Thanks given
    152
    Thanks received
    413
    Rep Power
    462
    Ooo I was so close to catching a decease! Do what belz said or there are lots of tuts to add mp3 on google. Just search. Then add a command client sided, should be in client.java or something




    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    Wage's Avatar
    Join Date
    Mar 2014
    Posts
    58
    Thanks given
    33
    Thanks received
    14
    Rep Power
    97
    Quote Originally Posted by Ascenda View Post
    You could use something like the following for playing .wav files:

    Code:
    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("./data/cache/sound.wav").getAbsoluteFile());
    Clip clip = AudioSystem.getClip();
    clip.open(audioInputStream);
    clip.start();
    JLayer is a nice library for playing MP3 files, and has quite a bit of documentation.
    Thank you for the help, wonder if it would be possible to randomly pick a different track after one has finished playing from the same folder automatically.
    Reply With Quote  
     

  5. #4  
    Registered Member
    Wage's Avatar
    Join Date
    Mar 2014
    Posts
    58
    Thanks given
    33
    Thanks received
    14
    Rep Power
    97
    Quote Originally Posted by Ascenda View Post
    Certainly, you could do something like this to play a random track:

    Code:
    /* List all the files in the directory */
            File[] files = new File("./data/sounds/").listFiles();
    
            /* Choose a random file number */
            File audio = files[new Random().nextInt(files.length)];
    
            /* Check the file is a wav */
            if (audio.getName().endsWith(".wav")) {
    
                /* Play the sounds */
                try {
                    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(audio.getAbsoluteFile());
                    Clip clip = AudioSystem.getClip();
                    clip.open(audioInputStream);
                    clip.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
    That's neat I'll use it when I get it working, as I said I'm fairly new to Java and I really appreciate you making the notes so I'd be able to understand it.
    Reply With Quote  
     

  6. #5  
    Android/Java/Meteor/Node
    Orbyt's Avatar
    Join Date
    Oct 2013
    Posts
    335
    Thanks given
    25
    Thanks received
    21
    Rep Power
    11
    So I just wrote some code after reading this thread and got it working playing .wav files, so if you need some help implementing this just hit me up.
    Reply With Quote  
     

  7. Thankful user:


  8. #6  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    learn yourself noob.

    Skype meh bru
    Reply With Quote  
     


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. Music command
    By Genesis in forum Requests
    Replies: 2
    Last Post: 04-08-2011, 04:52 AM
  2. Music system + Command
    By ZRPS in forum Snippets
    Replies: 12
    Last Post: 02-12-2011, 05:35 AM
  3. Music System And Command!!!!
    By ZRPS in forum Tutorials
    Replies: 3
    Last Post: 02-24-2010, 07:49 AM
  4. Music command by Invalid123
    By ZRPS in forum Snippets
    Replies: 16
    Last Post: 02-22-2010, 12:00 AM
  5. [508] Finding Music (command)
    By lukas265 in forum Configuration
    Replies: 8
    Last Post: 06-17-2009, 01:17 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •