Thread: My Audio System :)

Results 1 to 10 of 10
  1. #1 My Audio System :) 
    PokeFrontier Java Developer

    Pokemon's Avatar
    Join Date
    May 2011
    Posts
    2,733
    Thanks given
    494
    Thanks received
    801
    Discord
    View profile
    Rep Power
    1242
    Code:
    package com.adventurequest.io.sound;
    
    import java.util.logging.Logger;
    
    public class Audio 
    {
    	
    	public static final Logger logger = Logger.getLogger(Audio.class.getName());
    	
    	private String extensionType;
    
    	private String fileName;
    
    	public Audio(String theExtensionType)
    	{
    		if(isValidExtension(theExtensionType))
    		{
    			setExtensionType(theExtensionType);
    			logger.info("Audio extension " + theExtensionType + " has been constructed");
    		}
    		else
    		{
    			logger.info("Extension Not supported!");
    		}
    	}
    	
    	private boolean isValidExtension(String theExtensionType)
    	{
    		if(theExtensionType.equals(AudioExtension.MIDI) ||
    				extensionType.equals(AudioExtension.MP3))
    		{
    			return true;
    		}
    		else
    		{
    			return false;
    		}
    	}
    	
    	private String setExtensionType(String theExtensionType)
    	{
    		if(theExtensionType.equals(AudioExtension.MIDI))
    		{
    			extensionType = theExtensionType;
    			return extensionType;
    		}
    		return null;
    	}
    	
    	public String getExtensionType()
    	{
    		return extensionType;
    	}
    	
    	public String setFileName(String theFileName)
    	{
    		fileName = theFileName;
    		return fileName;
    	}
    
    	public String getFileName()
    	{
    		return fileName;
    	}
    	
    	public void play(Midi midiFile)
    	{
    		midiFile.play();
    	}
    	
    }
    Code:
    package com.adventurequest.io.sound;
    
    import java.io.File;
    import java.io.IOException;
    
    import javax.sound.midi.InvalidMidiDataException;
    import javax.sound.midi.MidiSystem;
    import javax.sound.midi.MidiUnavailableException;
    import javax.sound.midi.Sequence;
    import javax.sound.midi.Sequencer;
    import javax.sound.midi.Synthesizer;
    
    /**
     * Midi file playing.
     * @author Tony.
     */
    public class Midi {
    
    		/**
    		 * File directory.
    		 */
    		private static final String defaultFileDirectory = "res/music/";
    		
    		private File fileDirectory;
    		
    		private String archiveDirectory;
    		
            /**
             * The name of the midi file.
             */
            private String fileName;
    
            /**
             * The Sequence object.
             */
            private Sequence sequence;
    
            /**
             * The Sequencer object.
             */
            private Sequencer sequencer;
    
            /**
             * The Synthesizer object.
             */
            @SuppressWarnings("unused")
    		private Synthesizer synthesizer;
            
            /**
             * Constructs a Midi object using the default file directory.
             * @param theFileName the name of the file
             */
            public Midi(String theFileName)
            {
            	archiveDirectory = defaultFileDirectory + theFileName;
            	fileDirectory = new File(archiveDirectory);
            }
            
            /**
             * Constructs a midi object using the specified filedirectory
             * @param theFileDirectory specified file directory to the file archive.
             * @param theFileName name of the midi file.
             */
            public Midi(String theFileDirectory, String theFileName)
            {
            	archiveDirectory = defaultFileDirectory + theFileDirectory + theFileName;
            	fileDirectory = new File(archiveDirectory);
            }
            
            /**
             * Sets the name of the midi file
             * @param theFileName the name of the file
             * @return fileName
             */
            public String setFileName(String theFileName)
            {
            	return fileName = theFileName;
            }
            
            /**
             * Starts the midi file to play.
             */
            public void play()
            {
    			try
    			{
    				sequence = MidiSystem.getSequence(fileDirectory);
    
    	    	     // Get default sequencer.
    	    	    sequencer = MidiSystem.getSequencer(); 
    	    	    sequencer.setSequence(sequence);
    	    	    sequencer.open();
    	    	    sequencer.start();
    			}
    			catch (InvalidMidiDataException e) 
    			{
    				e.printStackTrace();
    			} 
    			catch (IOException e) 
    			{
    				e.printStackTrace();
    			}
    			catch(MidiUnavailableException e)
    			{
    				e.printStackTrace();
    			}
            }
            
            /**
             * Stops the midi file from playing.
             */
            public void stop()
            {
            	sequencer.stop();
            	sequencer.close();
            }
    
    		public String getFileName() {
    			return fileName;
    		}
    
    }
    Code:
    package com.adventurequest.io.sound;
    
    public class AudioExtension
    {
    
    	public static final String MIDI = ".mid";
    	
    	public static final String MP3 = ".mp3";
    }
    Pretty simple to use it works fine on my 2D game (currently supports Midi Files only) i will add volume support and mp3 support later on I'm still progressing on this

    [Only registered and activated users can see links. ]



    Pokemon loves his
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,108
    Thanks given
    2,402
    Thanks received
    2,825
    Rep Power
    4604
    Why not use something with more support for newer devices?
    Reply With Quote  
     

  4. #3  
    PokeFrontier Java Developer

    Pokemon's Avatar
    Join Date
    May 2011
    Posts
    2,733
    Thanks given
    494
    Thanks received
    801
    Discord
    View profile
    Rep Power
    1242
    Quote Originally Posted by Jason View Post
    Why not use something with more support for newer devices?
    Oh... like? I am going to update this at a later date so it supports mp3 format files as well but im open to suggestions

    [Only registered and activated users can see links. ]



    Pokemon loves his
    Reply With Quote  
     

  5. #4  
    q.q


    Join Date
    Dec 2010
    Posts
    6,535
    Thanks given
    1,072
    Thanks received
    3,534
    Rep Power
    4752
    Code:
    public abstract class AudioExtension
    {
    
    	public static final String MIDI = ".mid";
    	
    	public static final String MP3 = ".mp3";
    }
    ?
    Reply With Quote  
     

  6. #5  
    PokeFrontier Java Developer

    Pokemon's Avatar
    Join Date
    May 2011
    Posts
    2,733
    Thanks given
    494
    Thanks received
    801
    Discord
    View profile
    Rep Power
    1242
    Quote Originally Posted by Harlan View Post
    Code:
    public abstract class AudioExtension
    {
    
    	public static final String MIDI = ".mid";
    	
    	public static final String MP3 = ".mp3";
    }
    ?
    Forgot to remove abstract i was planning on adding some abstract methods but i changed my mind.

    [Only registered and activated users can see links. ]



    Pokemon loves his
    Reply With Quote  
     

  7. #6  
    Banned

    Join Date
    Apr 2013
    Posts
    1,620
    Thanks given
    410
    Thanks received
    474
    Rep Power
    0
    Quote Originally Posted by Pokemon View Post
    Forgot to remove abstract i was planning on adding some abstract methods but i changed my mind.
    Could be useful if you finish it up dude, thanks for sharing.
    Reply With Quote  
     

  8. #7  
    PokeFrontier Java Developer

    Pokemon's Avatar
    Join Date
    May 2011
    Posts
    2,733
    Thanks given
    494
    Thanks received
    801
    Discord
    View profile
    Rep Power
    1242
    Quote Originally Posted by trees View Post
    Could be useful if you finish it up dude, thanks for sharing.
    It works im currently using it on my 2d game this is how you use it

    Code:
    Audio audio = new Audio(".mid");
    				audio.play(new Midi("RS_OLD.mid"));

    [Only registered and activated users can see links. ]



    Pokemon loves his
    Reply With Quote  
     

  9. #8  
    Banned

    Join Date
    Apr 2013
    Posts
    1,620
    Thanks given
    410
    Thanks received
    474
    Rep Power
    0
    Quote Originally Posted by Pokemon View Post
    It works im currently using it on my 2d game this is how you use it

    Code:
    Audio audio = new Audio(".mid");
    				audio.play(new Midi("RS_OLD.mid"));
    I meant for playing mp3's and such but thanks, add that to first post. Someone will want it eventually.
    Reply With Quote  
     

  10. #9  
    Banned

    Join Date
    Apr 2012
    Posts
    3,259
    Thanks given
    2,554
    Thanks received
    832
    Rep Power
    0
    Looking forward to the MP3-support!
    Thanks for sharing!
    Reply With Quote  
     

  11. Thankful user:


  12. #10  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,108
    Thanks given
    2,402
    Thanks received
    2,825
    Rep Power
    4604
    Quote Originally Posted by Pokemon View Post
    Oh... like? I am going to update this at a later date so it supports mp3 format files as well but im open to suggestions
    Credits to the author of this > [Only registered and activated users can see links. ]
    Reply With Quote  
     

  13. Thankful user:



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. audio system in my civic
    By gnarly in forum Spam
    Replies: 17
    Last Post: 12-16-2011, 09:56 PM
  2. my dueling system
    By I'm me bitch in forum Help
    Replies: 4
    Last Post: 03-06-2009, 12:47 AM
  3. My Operating System!
    By MattOS in forum Application Development
    Replies: 7
    Last Post: 02-19-2009, 02:47 AM
  4. my ranging system
    By killamess in forum Tutorials
    Replies: 8
    Last Post: 12-19-2008, 06:04 AM
  5. My Chat System i've made for my Client
    By Hybrid Isle in forum RS2 Client
    Replies: 10
    Last Post: 12-01-2007, 01:57 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
  •