Problem with playing sound files

Discussion in 'Java' started by Christian Kremser, Mar 8, 2005.

  1. I have a problem with playing sound-files (wav-files) from my
    application. The application should play a short (about 1-2 sec
    long) sound-file (the existence of the files ich checked) from a
    list each time the user pushes a button (the index of the list is
    changed for each button press). The problem I have is, that it
    sometimes works and plays the sound and sometimes it doesn't play
    the sound and there is now error thrown. The part of my code
    which plays the sound is as follows:

    try {
    URL completeURL = new URL("file:" +
    FileList[actIndex]);
    AudioClip audioClip = Applet.newAudioClip(completeURL);

    audioClip.play();
    } catch (MalformedURLException e) {
    System.err.println(e.getMessage());
    }

    Has anybody an idea what is wrong with this? How can I make sure
    ensure that the file is completely loaded and ready for playing
    (if (audioClip==null) didn't bring any improvement)? Or, how can
    I determin if the AudioClip has finished playing?

    Thanks in advance for any help!
    Cheers,
    Christian.
     
    Christian Kremser, Mar 8, 2005
    #1
    1. Advertising

  2. Christian Kremser wrote:
    > I have a problem with playing sound-files (wav-files) from my
    > application. The application should play a short (about 1-2 sec long)
    > sound-file (the existence of the files ich checked) from a list each
    > time the user pushes a button (the index of the list is changed for each
    > button press). The problem I have is, that it sometimes works and plays
    > the sound and sometimes it doesn't play the sound and there is now error
    > thrown. The part of my code which plays the sound is as follows:
    >
    > try {
    > URL completeURL = new URL("file:" + FileList[actIndex]);
    > AudioClip audioClip = Applet.newAudioClip(completeURL);
    > audioClip.play();
    > } catch (MalformedURLException e) {
    > System.err.println(e.getMessage());
    > }
    >
    > Has anybody an idea what is wrong with this? How can I make sure ensure
    > that the file is completely loaded and ready for playing (if
    > (audioClip==null) didn't bring any improvement)? Or, how can I determin
    > if the AudioClip has finished playing?
    >
    > Thanks in advance for any help!
    > Cheers,
    > Christian.


    Christian:

    I've seen the error too on Windows machines. I don't know how to solve
    it other than trying to use the Clip interface instead of AudioClip.
    The problem appears to be more pronounced if you are playing one
    AudioClip right after another and it may be a browser problem.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Mar 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Clarke

    Sound lost when playing AVI files

    Ron Clarke, Feb 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    350
    Ron Clarke
    Feb 24, 2004
  2. Replies:
    0
    Views:
    507
  3. fuli open

    Playing Sound Files

    fuli open, Mar 25, 2007, in forum: HTML
    Replies:
    4
    Views:
    458
    =?iso-8859-1?Q?Kim_Andr=E9_Aker=F8?=
    Mar 26, 2007
  4. Ravi

    Playing sound files

    Ravi, Apr 6, 2008, in forum: Java
    Replies:
    8
    Views:
    424
    Michael Jung
    Apr 8, 2008
  5. Replies:
    6
    Views:
    109
    getburl
    Feb 3, 2007
Loading...

Share This Page