How to make audio.play() wait

Hi,
I use audio.play() in a program that will randomly play the (wav) files in a directory.
It all works works - except audio.play() doesn't wait for one song to finish before it goes on to the next.
Should a spawn a thread with audio.play() in it?
If so, is there a simple way?
Or, is there another way to tell/force audio.play() to wait till the song is finished?
Here is the portion of the code:
       //--- Shuffle by exchanging each element randomly
       for (int i=0; i<nFiles.length; i++) {
           int randomPosition = rgen.nextInt(nFiles.length);
           int temp = nFiles;
nFiles[i] = nFiles[randomPosition];
nFiles[randomPosition] = temp;
//System.out.println(nFiles[randomPosition]);
//System.out.println(path_chld[temp]);
try {
Uaudiofile = new URL("file:" + path_chld[temp]);
audio = Applet.newAudioClip(Uaudiofile);
//audio.wait();
audio.play();
Thread.sleep(2000);
catch (Exception e) {
//WriteError WEbadcommand=new WriteError("playrand failed trying to get the song file URL");
System.out.println("playrand Error creating URL, see log for more detail: " + e);
Thanks, Matt                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

matt_thumper wrote:
..All you have to do is submit the audio file as an independent process:If that 'SubmitProcess' class uses Runtime.exec() to gain a process, then you should add..
"And digitally sign the code, and convince the end user to agree to run the code."
Hope this helps.No, it does not really help the bigger scheme of things to have such poor strategies listed as a solution.
You have already been given a pointer to the API that would enable this ability in a sand-boxed applet. Even better than waiting a defined time for the sound to end, the Java Sound API offers listeners that will be informed when a sound has finished playing.

Similar Messages

  • How do I make audio play through both headphones in garageband?

    How do I make audio play through both headphones in garageband?

    C∆NOK∆N wrote:
    How do I make audio play through both headphones in garageband?
    http://www.bulletsandbones.com/GB/GBFAQ.html#leftspeakeronly
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • How to make mplayer play 3gp type files ??

    how to make mplayer play 3gp type files ??
    I downloaded a Japanese blue movie by amule, but I cannot play it!

    Army wrote:Actually, a few weeks ago, opencore-amr went into [extra] and ffmpeg and mplayer are being compiled against it, so Arch's mplayer should support 3gp files ootb including audio. Video playback was never an issue, because 3gp is just a container, the video codec is usually h263 or h264, which are no problem for mplayer.
    Very new versions of FFmpeg have native amr-nb support. I'm not sure if it happened before or after the most recent FFmpeg bump in the repos.

  • Macbook pro to HDTV, video is working but audio is not working, how to make audio work as well

    Macbook pro to HDTV, video is working but audio is not working, how to make audio work as well

    If you use an HDMI cable, the audiostream will be integrated, so there will be sound when using an HDMI cable!
    Not necessarily.  That only works as stated if you have one of the most recent MBP's that has a built-in HDMI port.
    If the MBP only has a Thunderbolt or miniDisplayPort, you need an appropriate adapter cable and even if you use an HDMI adapter or cable to connect to your HDTV there is no guarantee it will carry audio.  You have to determine if your specific MBP model supports audio out through its miniDisplayPort or Thunderbolt output, and whether the adapter does likewise.

  • I just installed an update on my iPhone and since then the choice to repeat music, or not, has disappeared and it automatically plays songs and albums on a loop. Anyone know how to make it play an album or song just once?

    I just installed an update on my iPhone and since then the choice to repeat music, or not, has disappeared and it automatically plays songs and albums on a loop. Anyone know how to make it play an album or song just once?

    Basics from the manual are restrt, reset, restore.
    Have you tried each of these?

  • How to Make Audio Books

    Hi,
    I'm not sure if this is the correct place for this topic but I have a 80 GB Black Classic and was wondering how to make a audio book to add to my iPod.
    I have several audio books on CD that have numerous chapters in them. Is there some type of conversion program to convert these to files that can be loaded onto the iPod or are they just mp3 files when added? If they are just mp3 files, will they load onto the music playlist or how due you make them show up in the Audio books menu?
    Adding files from a CD does not seem to be a problem as far as converting or ripping them to iTunes to be then synced to the iPod, but I do not know if a different type of file is needed other than mp3 to be able to play them as a audio book.
    Any help on this matter would be appreciated.
    Thank you in advance
    Mr. Hoz

    If you had a Mac, you could take it a step further and add chapter like Audible does. I came across a a AppleScript called Join Together which uses a tool from Apple called ChapterTool. Basically, you select the files to join and run Launch Join Together from the iTunes script menu. A dialog box pops up allowing to set the Artist, track info, release year, Album, etc. It also lets you set the output bit rate, frequency, and stereo/mono. It will either output a .m4a file (music) or a .m4b file (audiobook). If you have Apple's ChapterTool install, it will have an option to add chapter names based ont he song titles.
    Example: I have a dramatized version of the NIV Bible which wad a separate mp3 file for each chapter. So, it was broken into 1189 files:
    Song : Album
    Genesis 01 : 01 Genesis
    Genesis 02 : 01 Genesis
    Genesis 03 : 01 Genesis
    Exodus 01 : 02 Exodus
    Exodus 02 : 02 Exodus
    Exodus 03 : 02 Exodus
    Revelation 20 : 66 Revelation
    Revelation 21 : 66 Revelation
    Revelation 22 : 66 Revelation
    After using Join Together, I now have only 68 .m4b files, one for every book except Psalms which I split into three parts (001-050, 051-100, 101-150). Now when I select oneof the books on the iPod, a list of chapters are shown except for r the 5 books that only have one chapter (Test: name the 5 books without looking them up. .
    I in the proces of doing this for more books which I kept the individual chapter files like _Teach Yourself Norwegian_ (2 CDs) and two _Birding By Ear_ books (3 CDs each).
    For some reason the Join Together script errors out about 10% of the time and I have to re run it. I haven't tried to troubleshoot the issue, yet. Also at the beginning when it starts to join the tracks, the script plays all of the files being joined all at the same time for about 10 to 30 seconds. What a noise that is!
    Enjoy life,
    Steven

  • How to make sound play in loop

    Hi
    How can i make sound play in loop? Is there any property in class SoundChannel responsible for this or i have to write my own function?

    Using the sound Object there is a property you can pass in which asks for number of Loops
    Play(startPosition:Number,LOOPS:int,SoundTransform)
    or you can create your own method that listens to SoundComplete and then trigger play again.  which in my opinion is the best to do because when you play a sound with a loop, and choose to have is begin at a position other than 0  then the loop will play starting from where you set the position.

  • How to make iDVD6 play same music throughout a complex menu?

    How,
    I´m new to Mac and iDVD and was wondering how I make a music file play as the background sound throughout a complex menu (menu with submenus) ? So that the music keeps playing even if you go in to a submenu.
    Cheers!

    You can drag the music file separatly into each menu and submenu. You would get the same music playing in each submenu but it probably won't pick up at the same point where it left off in the previous menu.
    I don't know of any other way to make all the menus play the same music, but perhaps others on this forum will have some comments.

  • How to make a slide wait until user has answered a question correctly, even after activating a smartshape?

    Background:
    I have created a quiz in which the user must answer each question correctly before proceeding to the next slide. This is what I did:
    Set preferences to Settings > Required > Answer All - The user must answer every question to continue
    Set the number of attempts on the question level to Infinite
    Made the Next button invisible and disabled the playbar
    This way, the user can only proceed to the next question slide with the Submit process – and, since attempts are infinite, that means only after successfully answering the question.
    Current goal: 
    I want the user to be able to click on a prompt for a hint. To set this up, I did the following:
    Created a smartshape labeled “click_for_hint” displaying text that says, “Click here for a hint”
    Created a smartshape labeled “hint” displaying text hint
    Set “click_for_hint” to show “hint” on success
    Now, when the user clicks on the text that says, “Click here for a hint,” the hint pops up. So, that works – awesome! However, once the hint is activated, I would like for the user to be able to continue infinite attempts until successfully answering the question… and only then, after answering correctly, proceed to the next slide.
    The problem:
    If the user has submitted one or more incorrect answers and then activates the hint, the slide no longer waits until the user has answered the question correctly. Instead, it automatically resumes playing, proceeding to the next slide. I tried setting the smartshape “hint” to pause on success, but that did not work.
    Is there a way to make the slide wait until the question is answered correctly before proceeding to the next slide, even after the hint has been activated?

    Are you aware of the fact that your Required setting can cause problems, blocking the user? It is also totally unnecessary, because you have infinite attempts on question level, and did hide the Next button (hope you don't need Review, otherwise I would recommend not to hide that button but to drag it under the Clear button: Question Question Slides in Captivate - Captivate blog)
    The hint problem is linked with the fact that a simple action will release the playhead. I would like to see the timeline of the slide, to compare the pausing points of the shape button and the question slide. And maybe this blog post can also clarify difference between simple/advanced: Why choose Standard over Simple action? - Captivate blog
    As for shape buttons on question slides: Buttons on Question/Score Slides in Captivate 6? - Captivate blog

  • How to make audio cd images in leopard?

    I'm not trying to duplicate music. much of my music doesnt have album art and track info. its stored as mp3 in itunes. itunes refuses to pull up track info as they were not imported by it. so what i am trying to do is make audio cd copies of it and then reimport it to itunes. now, i have like 2000 songs. burning an actual disk would be a pain. in windows i would normally use nero to make an audio cd 'image' which can be mounted into a virtual drive.
    using disk utility i figured out how disk images of cd and dvd sizes can be made but the burn disk option (in itunes) only shows the super drive burner to burn an audio cd image to. any help?
    Neerav Kothari
    Message was edited by: AceNeerav

    i.3d wrote:
    This hardly clears my doubt, however, my point stands, if the info is NOT in an MP3, burning it to a disc OR creating a CD image is NOT going to help you (or iTunes) find the unique CD ID and get the missing info. NO, NO, NO
    There's no "unique CD ID". All iTunes does is look at the number and the length of each track on the CD, and measure that against what's in the online database. The closest match is offered up. If there's nothing close, then nothing is offered up.
    I took a vinyl record and imported the whole thing as an AIFF file. I chopped up the tracks into little bits, and then used Toast to burn the results to a CD. iTunes recognized it as a commercial CD release of the same album, and downloaded the correct artwork and all the track names. I was blown away the first time it happened, and it has happened again several more times with various old vinyl albums.
    It hasn't worked every time, but it has worked enough times for me to believe that the OP will have luck with his .mp3 files if he can burn them into a playlist that closely resembles the original commercial CD.

  • How to Make Audio Video Broadcasting Programe using JMF

    hi i m newto java programing i wan to know can any one help me out how to transimit audio and video over netwrok from one pc to other computer voer the network . i m using my webcam to transmit video can any one of u email me the code if any one has made such application like this .. my email is [email protected]

    Well you've found the root of your problem. It's not necessary the JMF. It's when you make a jar file, you need to include the dependencies. I don't think it' legal to include the JMF in a program you sell or distribute, so be careful there.
    However, to include dependencies in jar files is not a hard task. The simplest method is to unjar the dependency and place it at the top or your classpath; then make a jar that includes both your program, and the dependency.
    A more long term solution is to use a build system such as ant or maven to create the package using available scripts or plugins. The "Uberjar" plugin for maven comes to mind.
    -vito

  • HOW TO MAKE AUDIO SHOW THE SOUND WAVES?

    I was wondering if it was possible to show the sound waves on the audio track, whenever I plug in audio I cant seem to figure out how to make it show like it does in other programs such as Adobe Premiere? Thanks!

    Option-Command-W, if you're the keyboard type
    Otherwise, there's button right by the track height selector buttons, at the bottom left of the Timeline.

  • How to make audio file to use as ringtone on iPhone 5

    Does anyone know how to make a file and then make it a ringtone?

    Make sure iTunes prefs > Import settings is set to AAC.
    In iTunes, find the song you want and note the start/stop time you want the ring tone.
    Right click - get info, click the Options tab and set the start/stop times as above. (Note a 30 second max for ringtones)
    Right click - Create AAC version. This creates a new file.
    Drag this new file from the iTunes window to the desktop.
    Delete the new file from iTunes and also select Delete from hard drive.
    On the desktop, rename the file to what_ever_you_want.m4r (first part you can change to whatever you want & change the extension to .m4r).
    Drag the file back to the iTunes library at top left.
    Make sure iTunes prefs > General has Tones ticked.

  • How can I make audio play through my Macbook Pro while my Apple TV is on

    My Macbook Pro has now defaulted to my Apple TV as its source of audio while on the same network. If I attempt to switch it to internal speakers by clicking option and the volume button, it will not stay changed to internal speakers. This would be ok, except the audio comes out as very choppy from the apple tv as well. Does anyone have any suggestions as to how to play audio through my macbook again?

    appletv can access compatible media from a running computers shared itunes lib
    you can't sync movies to the appletv as it only have storage for cache

  • How to make clips play faster/slower?

    Hi, I recorded a road while driving on it. I want to use it for the beginning of a video but I don't want it to play at real-time speed. I want it to move faster than real time. How can I make this happen on imovie? how do I compress the clip (about 10 minutes) into something more like 5 minutes? I don't want to cut the clip, I want to play the whole thing but I want it to just move faster. It would also be cool because this way I could also learn to make things go in slow motion.

    How can I make this happen on imovie?
    If you want to do this from within iMovie, use the previous version. Basically, playback speed can be modified by adding your video to an audio clip having a duration or selected segment duration for which you want the video to play and scaling it to the duration of the audio using the QT Pro "Add to Selection & Scale" Edit menu option. You can also reset the playback using the fee JES Deinterlacer utility. (Search the forum for URL to Karsten Schlüter's site area where he has documented many common "Tips and Tricks" for use with iMovie '08.)

Maybe you are looking for

  • Unable to generate Pdf report for crystal 9/10  in Windows 2012 (Standard) server with Times New Roman font. With same font, report getting generated in excel, text, csv format in Windows 2012.

    For Times New Roman font in Windows server 2012 R2 (Standard), crystal 9/10 report in pdf format is not getting generated. When we change the font for specific report like Arial, Calibri , Cambria then pdf report getting created. In Windows 2008 R2,

  • Heap Error during Windows OCIEnvCreate() call

    During a call to: OCIEnvCreate(&m_handles.m_pOCIEnv,                          OCI_THREADED | OCI_OBJECT,                          NULL,                          NULL, NULL, NULL,                          0, (dvoid **)0); A crash occurs which reports

  • What is wrong in my JSP?

    Hi, Please see the code below. The problem I am facing is when the User already exists in the database, I am letting the user know that there is already an user with that name and asks him / her to repeat filling up the form again(" using printConten

  • Request for PhotoCD support

    Now that Kodak apparently isn't going to update the PCD acquire module for Intel Macs, I wanted to put in a request that the next rev of DNG convert the PhotoYCC image pack into DNG. I think this is possible after a conversation with Thomas awhile ba

  • JLabel Text merges into JComboBox - GBLayout bug?

    Hello, http://666kb.com/i/ayv9fbt03b8v1bkcy.png as you can see the text of the JLabel goes into the JComboBox, buy why? The Code looks ok to me: panel3.setLayout(new GridBagLayout());               addJComponentToJPanel( panel3,movieFormatLB       ,0