Results 1 to 11 of 11

Thread: AudioClip

  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default AudioClip

    I'm trying to play an audio clip, but I can't. Does the AudioClip support only .au files?

    :confused:

    package homenetwork.bkr.training;
    import java.awt.*;
    import javax.swing.*;
    import java.applet.*;

    @SuppressWarnings("serial")
    public class Chart extends JApplet {

    public void init()
    {
    EventQueue.invokeLater(new Runnable()
    {
    public void run()
    {
    ....

    AudioClip clip = getAudioClip(getCodeBase(), "C:\\audio\\picchi22.au");
    play(clip);

    ...
    }
    });
    }
    }

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    A Quote from Sun's FAQ on Java Sound

    Java Sound supports the following audio file formats: AIFF, AU and WAV. It also supports the following MIDI based song file formats: SMF type 0 (Standard MIDI File, aka .mid files), SMF type 1 and RMF.
    The file types above would be the one's supported by the AudioClip Interface.

    Not sure why it doesn't play, I've never used the Sound API before, though I've read the docs (sort of)

    Also, you probably don't want to have the @SuppressWarnings("serial"). You are probably better off using the standard private static final long serialVersionUID = 1L instead
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default

    Here is my code I use for making a audiochip run

    Before using this code I would but the au file where your source code file is to make it easier to access since call you will need is filename.au instead of all that c://umm/ok//hereithink

    You already have the import statements
    in your declarations make a AudioChip

    Java Code:
    //Here an Example
    AudioChip music;
    
    //I would but this in your init personally instead of your run
    music.this.getAudioClip(this.getCodeBase(),"musicfile.au");

  4. #4
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Didn't work...

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.applet.*;
    
    public class Chart extends JApplet {
    
    	AudioClip music;
    	
    	public void init()
    	{
    		music.WHAT?
    	}
    	
    
    }

  5. #5
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default

    just copy and paste this line it should work if not it might have to be a wav since I never used au

    music.this.getAudioClip(this.getCodeBase(),"picchi 22.au");

  6. #6
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    Java Code:
    iimport java.awt.*;
    import javax.swing.*;
    import java.applet.*;
    
    public class Chart extends JApplet {
    
    		
    	public void init()
    	{
    		AudioClip music;
    		music.this.getAudioClip(this.getCodeBase(), "picchi22.au");
    	}
    	
    
    }
    java.lang.Error: Unresolved compilation problem:
    music cannot be resolved to a type

    at Chart.init(Chart.java:11)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

  7. #7
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default

    Did you place the music file in the same folder as your source code and what IDE are you using

  8. #8
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    I placed the music file in the same folder as the source code; I usually prefer to place it in some \audio sub-folder of the solution though.

    Eclipse 3.5.0.

  9. #9
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default

    Can u try just taking the J away from JApplet and just make it Applet

    public class Chart extends Applet

    Because that the onl thing I think could mess it up

  10. #10
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    still doesn't work; see for yourself

  11. #11
    quickfingers is offline Member
    Join Date
    Dec 2007
    Posts
    21
    Rep Power
    0

    Default

    I see my mistake now

    this the line

    music=this.getAudioClip(this.getCodeBase(), "picchi22.au");

    Sorry I type it wrong

    Also after that line

    use these lines to play/ stop/ loop the file

    music.play(); Plays 1 time
    music.stop(); Stops music
    music.loop(); Loops file till applet stops

Similar Threads

  1. Volume of AudioClip
    By Fedor in forum New To Java
    Replies: 0
    Last Post: 04-25-2009, 04:16 PM
  2. Applet-Image,audioclip problem-pls help
    By samares in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 03:23 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
  •