How to play audio in an application?? (HELP ME PLEASE!!)

Hi! I'm studying computer science and I'm programming in Java for my last project of this period. I've been trying to play sound in an application but I haven't been able to. My teacher gave me a piece of code that looked like this:
try{
URL url=new URL("http://hostname/audio.au");
AudioClip ac=Applet.new AudioClip(url);
ac.play();
}catch (MalformedURLException e){
This is the code for my program:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.AudioClip;
import java.applet.AudioClip.*;
public class Sonido extends Frame implements AudioClip{
     public Sonido(){
          this.setSize(new Dimension(300,200));
          this.setTitle("Testing");
          this.setLayout(new BorderLayout());
          this.add(new Button("Music"), BorderLayout.CENTER);
          addWindowListener(new WindowAdapter(){
               public void windowClosing(WindowEvent e){
                    System.exit(0);
     public static void main(String [] args){
          Sonido sound=new Sonido();
          sound.show();
          try{
               URL url=new URL("C://toolate02.au");
               AudioClip ac=new AudioClip(url);
               ac.play();
          catch(MalformedURLException e){
It is only a test but I have to get it to work because the teacher wants the sound to play forever! (with loop() I guess). Anyway, I don't know how to implement the methods of the AudioClip interface. Any help would be great!!! Thank you very much.
Vanessa.

This is probably too late to help you, but if you're using Java 1.3 or higher, you can use the javax.sound.sampled package to play .au's, .aiff's, and .wav's (but not .mp3's... support for those comes from Java Media Framework [JMF] or QuickTime for Java [QTJ])
Anyways, this app plays a single file specified on the command line, like:
java SimpleSound mailbag.aiff
import javax.sound.sampled.*;
import java.io.*;
public class SimpleSound extends Object {
    public static void main (String[] args) {
        if (args.length < 1) {
            System.out.println ("Usage: SimpleSound <file-path>");
            return;
        try {
            Line.Info linfo = new Line.Info (Clip.class);
            Line line = AudioSystem.getLine (linfo);
            Clip clip = (Clip) line;
            File file = new File (args[0]);
            AudioInputStream ais = AudioSystem.getAudioInputStream(file);
            clip.open (ais);
            clip.start();
        } catch (Exception e) {
            e.printStackTrace();
}Works for me on Mac OS X. .aiff's sound good but .au's sound awful. Your mileage may vary.
More info on the JavaSound page -- http://java.sun.com/products/java-media/sound/index.html
--Chris (invalidname)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Play Audio File in application

    Hello all.
    Can anybody tell me how can I play some Audio File from my application?
    I think that it's impossible. (I can play Audio File only if i will use java.applet.AudioClip).
    I know that some classes in sun.*.*... can play Audio File.
    And I want to know why developers cann't make them easy of access.
    Thank you,
    Dmitry

    There are 2 ways you can play audio in an application. The of audio tools packaged with applets can be adapted to work in an application. Unfortunately, I do not know how to do this. I have had more success with sun.audio.*, but have been unable to find any documentation on it, which makes it very limiting.

  • I rented a movie on apple tv but it wont play on the tv. Help me please.

    I rented a movie on apple tv but it wont play on the tv. Help me please.  I want to see it but a message appears saying that an error occurred loading this content. What can I do?

    Have you tried a reboot?
    What is your connection speed via speedtest.net?
    Check istumbler or netstumbler to see about network interference
    Make sure DNS is set correctly (settings - general - network - configure DNS - automatic)

  • How to play audio recordings from Mac Word Notebook on a PC?? HELP!

    I recorded some conversations using Word for Mac Notebook template, that I want to send out to people who have PCs. When I save audio separately (Tools, audio, export audio) it creates an .mp4 format for the audio. The PCs don't recognize this! In Quicktime, Windows Media, etc. you always get error messages. How can you play an mp4 on a PC? Please help!!!

    user7029801 wrote:
    player.setMediaTime(new Time(15*60));
    player.start();Nothing jumps out as being wrong about the way you're doing this...
    Time has two constructors, one for seconds that takes in a double, and one for nanoseconds that takes in a long. I believe that "15*60" would be interpreted as a long, and thus you're setting the media time to 900 nanoseconds...which would be the beginning.
    You could fix the problem one of two ways:
    Cast to a double
    new Time((double)(15*60)));Or use the constants provided...
    new Time(15*60*Time.ONE_SECOND);

  • HOW to play flash inside java application program

    Do java provide any API for playing flash inside java application ?Pleae give me some help about it .Thank You ..

    pingyi wrote:
    Do java provide any API for playing flash inside java application ?Pleae give me some help about it .Thank You ..bro... I found out there from the internet... but you need to purchase it.
    hope it meets your expectation...
    JFlashPlayer is a Flash Player API Java package that lets developers play and interact with Adobe? Flash Player movies within Java applications. Advanced animations can improve the user experience and add to the professional appearance of an application. JFlashPlayer allows programmers to quickly add Flash movies to their Java application development for Windows.taken from: JflashPlayer

  • How to play audio tracks with mainstage

    Hello, newbie to mainstage-looked around site but didn't find too much.
    I have a gig in a few weeks need help fast please!- Looking to play either multiple, or even just one long 30 minute track in mainstage and then play with fx live. terminology in user manual doesn't seem to say much about this. can i run an audio track in mainstage as a patch or something. Or run logic/audio track(s) through mainstage and then put fx on it? thanks

    I have not used an FC-300, but I have had a close look at its specifications. I don't think it is going to be a lot of use as a controller for MainStage.
    You have two 'expression' pedals; these can be assigned to control any two parameters in any patch eg two channel strip volumes; one bus send level & one FX parameter, etc. Useful, but limited in scope.
    The remaining pedals are foot switches. That means they will each allow you to do the following types of action:
    change patch up or down
    bypass any FX, synths or channel strips in a patch
    start & stop Ultrabeat
    any other similar type of action.
    What do you want the buttons to do?
    To use a foot switch to control a button:
    'Learn' a footswitch to a button (to begin with, stick to switches 1 -5. Ignore 6 - 10 until you are comfortable with the first five switches)
    when you have 'Learned' the switches in the Layout screen move to the Edit screen
    Here, take each button in turn & assign it to an action:
    e.g
    button 1 to Ultrabeat start/stop
    button 2 to Delay Bypass
    button 3 to 'Next Patch' (set at Concert Level)
    button 4 to 'Previous Patch' (set at Concert Level)
    I don't think that you will be able to do much more with the FC-300 than that. I hope someone will be able to prove me wrong.
    NB It doesn't matter what CC number the switches have in the FC-300. Once you have assigned them to a button, the switch should carry out whatever action the button is assigned to in MainStage. All you need to do is to make sure that no two buttons have the same CC number.

  • How to play audio with the phone receiver

    I have a strange question.
    I try to use my iPhone 4s (iOS8.1) for an audio tour in the art gallery.
    I am looking for a way to play iTunes audio and listening on your phone in the style of you put your ear on your phone... Dose this make sense?
    I want to play audio through not the phone speaker, but the phone receiver which you listening when you use your iPhone.
    I was looking for some app to do it,,, but I know this is very strange way of using iPhone, so I can't find any tips or apps....
    Please help!
    Thank you

    Not all HTML works on the iPad, and not all HTML that works on the iPad works in DPS. Whenever you create HTML, check first to see if it works in mobile safari. If it doesn't work in mobile safari, it won't work in DPS.
    Basic HTML, CSS and Javascript are supported in mobile safari. But if you are using Flash or Run Java Applets or sometimes even jQuery, your code won't work in mobile safari. Some HTML5 tags are not fully supported.

  • Dear sir / mam, i lost my iphone 4s how i can got it  can you help me please

    dear sir / mam, i lost my iphone 4s how i can got it  can you help me please

    If you had Find My iPhone enabled, you can locate the phone through PC.
    https://www.apple.com/uk/icloud/find-my-iphone.html
    http://support.apple.com/kb/ht5668

  • I can't open any of apps that already in my macbook pro such as App Store,iMovie,calendar and lot more . How do I solve this problems? help me please..

    When I click some of the apps that already in my Macbook Pro since the first time I bought this , it show up at the docks but in the next seconds it disappear and the apps won't opened . the apps that can't be opened are App Store , iMovie , PhotoBooth , Calendar , iBooks and lot more . I just use my macbook for just a week and I'm still new on macbook . help me please to solve this

    Please what, if any, error messages are displayed after the apps quit.

  • When I went to open photoshop gave error 16. How do I solve this problem? Help me, please.

    Not only is photoshop, are all that is installed in my computer. I need the programs for college studies, for I Design. Help me please.

    Amanda, as Gene has suggested, the initial error 16 indicates a Permissions problem.  Check this page for details
    http://helpx.adobe.com/x-productkb/policy-pricing/configuration-error-cs5.html
    But it would help to know exactly what version of Windows your are using, as well as what version of Photoshop.

  • Playing audio in an application

    How does one play an audio (.wav) referenced by an URL in a java application? I remember reading somewhere that Applet has an static method doing this, but was unable to find it from the API. Thanks in advance

    Wouldn't this be it?
    void play(URL url)
    Plays the audio clip at the specified absolute URL.
    Don't know whether it would work with .wav files, though.

  • How to play audio files in sequence?

    I have several audio books that I am trying to listen to on the new nano 6g. It seems that when one chapter is done playing, it restarts the same chapter instead of moving on to the next one in sequence. I have disabled shuffle, which I have never liked, but with the new design, it doesn't seem like there is a universal shuffle off setting, just the shake featue. I don't want ANY shuffle. How can I get this thing to play files in ORDER?
    thanks

    This is an interesting topic. Nobody dares to believe that Java can do good sound. I got all hooked up and studied it for an hour. I hope you or another will be able to use what I've found. It seems credible that Java have some great audio capabilities, but I haven't tested them all yet.
    http://java.sun.com/docs/books/tutorial/sound/playing.html
    has a great general introduction to sound in applications versus applets.
    If you are dealing with a limited set of sound files that you want to incorporate in, say, a game, convert them to .au or .wav files or another that can be read by the AudioClip class. A great conversion tool that I've used for some time is Goldwave. Fetch at at
    www.download.com
    Java Media Framework can do more than that, it can stream audio and do other stuff too. The procedure is as follows:
    1. Download JMF
    2. import javax.media.*;
    3. make a Manager
    4. get a Player from the Manager
    5. play something
    Morten Hjerl-Hansen
    founder
    www.gentleprotest.com
    www.kitcheneer.com
    developer
    www.zellsoft.com

  • How to play audio file in voice Modem

    Hi,
    I am developing IVR application. i want to run audio file whenever phone rings.
    caller should be able to hear the content of audio file.
    I am using voice modem DLINK DFM 562E++.
    Please give some idea how to implement it using JMF.
    Thanks in advance
    Pradeep

    @ mark
    as u said I am doing all these. but my problem is i do not get OK response back when i send AT+VLS=7 command to receive a call. AT+VLS=7 is needed to select device mode and enabling transfer and receive.
    when i send AT+VLS=7 after ring, it seems call is picked up but i do not get ok response back in my program.
    after this none of command gives ok response so i don't know whether my setting to play file is correct or not.
    i am doing this one by one...
    'Init' AT Command: 'ATE0V1S0=0&C1&D2+MR=2;+DR=1;+ER=1;W2<cr>'
    'VoiceMode' AT Command: 'AT+FCLASS=8<cr>'
    'EnableCallerID' AT Command: 'AT+VCID=1<cr>'
    'SpeakerPhoneON' AT Command: 'AT+VSP=1<cr>'
    SpeakerGain' AT Command: 'AT+VGS=255<cr>'
    'SpeakerPhoneVolume' AT Command: 'ATL=3<cr>'
    'SpeakerPhoneControl' AT Command: 'ATM=3<cr>'
    'VoiceGainTransmit' AT Command: 'AT+VGT=255<cr>'
    'SetupSampling' AT Command: 'AT+VSM=129,8000,0,0<cr>'
    after this if ring comes then i am sendnig AT+VLS=7 to serial port.

  • How to play videos in java application

    Hi... every one
    I want to write a java application to play videos ....Please guide me how to go about it..
    Thanks in advance...
    Rgrds
    Ravi. N

    [http://www.cs.odu.edu/~cs778/spring04/lectures/jmfsolutions/examplesindex.html]

  • How to play audio file in default player in j2me

    Hi ,
    I would like to implement Audio Streaming in Mobile application. I am record the voice using amr format and store
    local mobile memory and retrieve and play the file successfully, what is my requirements is, when i was play the
    file , i want to open the file in any default player in the mobile, the forward and backward control are use the default
    player control. is it possible to play the file in default player in j2me. please reply soon.
    With Regards,
    Ganesh Kumar
    Edited by: tlgkumar on Oct 23, 2008 11:55 AM

    Hi Ganesh,
    my suggestion to u is use existing streaming protocol that already support by MMAPI, thats RTSP/RTP protocol.
    u only need to configure existing streaming server like HELIX SERVER or DARWIN SERVER, and ENCODER like FFMPEG, HELIX PRODUCER, etc to encode ur live media / store file become RTP packet and then let server send that to ur client. u can use camera / TV turner also to capture live video and send that by streaming. So u dont need to make ur own server, except ur project need different protocol from that streaming server use.
    in client side, u can choose to use REAL MEDIA or make ur own player, Nokia already support RTSP protocol since S40 3rd edition and S50 2nd edition FP 3. so u dont need to parse by ur code RTSP message and RTP packet. u also can use forward and backward fiture too by that both streaming server.
    please read any RTSP / RTP standar protocol reference, i think it will be helpfull to u to make ur own system configuration ..
    -best regards-
    adek aidi

Maybe you are looking for

  • Sales Orders Outside Credit Horizon

    Hi everyone, My client has implemented FSCM credit management, using a Dynamic credit check with a 6-day credit horizon.  It was my understanding that for an order where the material availability date of every schedule line is outside the credit hori

  • How do I add a new email account?

    I installed Thunderbird today and have no email accounts set up yet. That is because by following the instructions in the help files, I was lead straight into a brick wall. I can't find a way to insert a screenshot of the help page. It says to: First

  • Is it possible to view information such as play count on Artist view in itunes 11?

    is it possible to view information such as play count on Artist view in itunes 11?

  • Authorization for GoTo Context Menu Item in BI 7.0

    Friends, I am looking for the authorization object that controls whether or not a user can see the 'GoTo' option in the context menu on a query cell.  I have a need to have it on for some users and off for others. Thanks in advance.  I will award poi

  • Mail missing plug-ins

    OK, strange one here.  I have several clients (Lion and Mountain Lion) that get the Missing Plug-ins in certain emails using Mail.app.  They are all using Exchange 2010 server, some setup w/ IMAP, others as Exchange server.  I know about the java tri