Play a sound many times in a short time

Hi,
i am using JMF 2.1.1e, and i wondered if there was some trick to play a sound many times in a short time.
The first method i used was:
     private static Thread t     = null;
     private static URL url;
     private static Player player;
     public static void playSound(String name)
          File mp3 = new File("./sounds/level5/"+name+".mp3");
          try { url = mp3.toURL(); } catch (MalformedURLException e) {e.printStackTrace();}
          // to prevent from multiple sounds playing at the same time
          if(t != null && !t.isInterrupted()) t.interrupt();
          t = new Thread()
               public void run()
                    try
                         MediaLocator ml = new MediaLocator(url);
                         player = Manager.createPlayer(ml);
                         player.addControllerListener(
                                   new ControllerListener()
                                        public void controllerUpdate(ControllerEvent event)
                                             if (event instanceof EndOfMediaEvent)
                                                  player.stop();
                                                  player.close();
                         player.realize();
                         player.start();
                    catch (Exception e) { System.out.println("Exception encountered!");}     
          t.start();
I wasn't really satisfied with such a method, since it often took two or three seconds before the sound start playing (maybe because my pc is slow, and the method takes too much memory) so i came up with another idea : storing the sound , calling the "start" method each time i need them, and re-preparing them for the next call short after the call to start; it gives :
static Player[] sounds = new Player[15];
// first initialization of a sound
sounds[0] = new Splay().generate("fac");
// call to the sound, the sound plays nearly immediately
sounds[0].start();
// reinitialization of the sounds, in order to prepare him for the next call
Splay.scheduleInit(0,"fac");
// methods used:
public static void scheduleInit(final int index, final String name) {
new java.util.Timer ().schedule (new TimerTask () { public void run () {
     Screen.sounds[index] = new Splay().generate(name);
}},500);
// and
     public Player generate(String name) {
          Player p = null;
          File mp3 = new File("./sounds/level5/"+name+".mp3");
          try { url = mp3.toURL(); } catch (MalformedURLException e) {e.printStackTrace();}
          try {
               MediaLocator ml = new MediaLocator(url);
               p = Manager.createPlayer(ml);
               p.realize();
          } catch (Exception e) { System.out.println("Exception !");}     
          return p;
it works better than the first one, but it's still not perfect ;
To resume, i need a code that easily allow to :
- Launch tracks fast
- Don't play many sounds in the same time (means that stops the currently played track before loading the new one)
- A player that handle MP3 would be really better compared to a wav player
Will be great if you have something like that
Thank you very much ^^
Message was edited by:
calvino_ind

You can follow the below steps to easily play a sound at runtime - like on mouseover.
1. Make sure your audio is imported in library and has a linkage name specified.
2. Open Windows Menu -> Code Snippets panel and expand HTML5 Canvas -> Event Handlers section.
3. Select your button on Stage and apply the MouseOver Event from Code Snippets to it.
4. In the MouseOverHandler function add the below line and test movie:
          playSound('audio_linkage_name');
If you still face problems let me know.
Also, you might want to go through the SoundJS documentation for more control with Audio in HTML5.

Similar Messages

  • How many times can you view a rental?!?

    What on earth?: Hit Play, and you have 24 hours to finish it — or play it as many times as you want. Rentals disappear when they expire, so they won’t take up storage space on your hard drive.
    So which is it? You can watch it as many times as you want or you must finish within 24 hours? I'm trying to figure out if its worth it or not.

    camoracer:
    I think one big difference is that the iTunes rentals do not involve a physcial DVD needing to be returned. The other is that many retail brick and mortar rental stores allow weekly rentals.
    The 24 hour thing is a deal breaker for me as well. I travel and sometimes I start to watch a movie and the flight lands. I don't have time to watch it on the business trip destination, so I wuld watch the rest of it on the flight back home. 24 hours does me no good.

  • My iphone 5 has no sound out the speakers, all it will do is play out alarm tone, all sound were Working this morning, I have re set my phone many times

    My iphone 5 has no sound out the speakers, all it will do is play out alarm tone, all sound were Working this morning, I have re set my phone many times, please help

    Hey Amiee_19,
    Thanks for the question. It sounds like your Ring/Silent switch may be toggled:
    Ring/Silent switch - iPhone
    http://help.apple.com/iphone/7/#/iph3bd01398
    Ring/Silent switch
    Flip the Ring/Silent switch to put iPhone in ring mode or silent mode .
    In ring mode, iPhone plays all sounds. In silent mode, iPhone doesn’t ring or play alerts and other sound effects.
    Important: Clock alarms, audio apps such as Music, and many games play sounds through the built-in speaker, even when iPhone is in silent mode. In some areas, the sound effects for Camera and Voice Memos are played, even if the Ring/Silent switch is set to silent.
    For information about changing sound and vibration settings, see Sounds and silence.
    Use Do Not Disturb. You can also silence calls, alerts, and notifications using Do Not Disturb. Swipe up from the bottom edge of the screen to open Control Center, then tap the Do Not Disturb button . See Do Not Disturb.
    If the above does not resolve your issue, see this article:
    iPhone: No sound or distorted sound from speaker
    http://support.apple.com/kb/TS5180
    Thanks,
    Matt M.

  • Sounds stops many times during playback with popping noises

    During start or playback of a song, Logic makes many times a popping sound after which the sounds is gone although the song keeps on playing. This also happens when I play on my keyboard while using software instruments. A short moment I hear the software instrument, then a popping sounds and no sound any longer although the midi meter shows that I am playing. What is wrong here?

    I have the same problem everyone here is describing.
    I bought a Jabra Extreme a few months ago (it supports A2DP) and I found that the audio keeps skipping on my iPhone 4. It skips every 5 seconds or so which rendered listening to music via bluetooth impossible. I figured it was a "compatibility issue" with the Jabra and abandoned its use for music.
    A couple of weeks ago, I decided to spring for a pair of JayBird bluetooth headphones. I figured this will help. Regretfully, the problem was back. This points the fault squarely at the iPhone.
    I have not tried turning the airplane mode on and off and will definitely give that a try. But I seriously don't think that should be the way a device capable of bluetooth audio streaming should work!
    Does anyone from Apple read these discussion threads? Will there be a fix?
    Maybe I should stop holding my breath.

  • Sound to play one at a time

    How do I make a command saying:
    if sound is playing - dont play sound, else, play sound?
    so that the sound effect only plays one at a time. So if holding down SPACEBAR for example, the sound will play and only after the sound finishes, can it loop if SPACEBAR is still pressed.
    Thanks in advance.

    Ok, I'll just copy and paste the relevent parts: (This is for a car-racing game)
    onClipEvent(enterFrame)
         HAND = Key.isDown(Key.SPACE)
         if (HAND) {
            speed  *= handbrake
            //sound
            var screechSnd:Sound = new Sound();
            screechSnd.attachSound("TireScreech");
               screechSnd.start();
            // SKIDDIES
            if (speed > MAXskiddisplay) {
            steer = steer_handbrake;
            if (!skidding) setLastpos();
            skidding=skid(HAND);}
            traction = handbrake_traction/surface; }
        else {
            skidding=false;
            traction = Math.max(traction_max, Math.abs((speed-MAXturnSpd)/surface))
            steer = steer_normal }
    So basically, when the handbrake (spacebar) is pressed, the handbrake effect will be applied to the car and it will skid (which works), but the problem is I also want a sound to play when it spacebar is pressed.
    The sound does play, however, when pressed, the sound plays many times over at the same time, rather than letting the sound finish for the sound to repeat itself again (if spacebar is still pressed - that is).
    Thanks again in advance

  • TS3276 I have no sound on my MacBook Air for sending and receiving messages. All sound settings have been checked and are OK. This problem has arisen many times and is intermittent in the sense that the sound returns and disappears for no apparent reason.

    I have no sound on my MacBook Air for sending and receiving messages. All sound settings have been checked and are OK. This problem has arisen many times and is intermittent in the sense that the sound returns and disappears for no apparent reason.

    Open System Preferences > Sound > Sound Effects
    Select:  Play user interface sound effects
    And make sure the Mute box is not selected.
    Now open Mail. From the Mail menu bar clik Mail > Preferences then select the General tab.
    Make a selection from the:  New messages sound  pop up menu.

  • I can not export imovie 11 to youtube. I tried exporting with quicktime so I could upload through youtube,but it had no sound. Very frustrating. When I upload through youtube it looks as if it is working, but I get no confirmation. Tried it many times.

    I can not export imovie 11 to youtube. I tried exporting with quicktime so I could upload through youtube,but it had no sound. Very frustrating. When I upload through youtube it looks as if it is working, but I get no confirmation. Tried it many times. What do I do?

    The "restore disk" is built into the Mac. See About Recovery.
    Need more specifics about what error messages you got while installing Adobe Flash.
    However, you can almost avoid Flash altogether by setting YouTube to play the HTML5 version instead.
    Click the Try something new! link at the bottom of the YouTube page.
    I don't know about the sound issue. Might be hardware as you think. Try other headphones to check.

  • My phone thinks it is connected to a dock all the time and will not play any sound or ring what do i need to do?

    my phone thinks that it is connected to a dock all the time and wont play ringtones or any other sound. I know that the speakers work because it will randomly play sound but for a very short amount of time and just recently stopped making sounds all together. the phone is almost brand new and has no damage I just bought it a few months ago. What can I do to fix the problem?

    Clean iPhone charging port with a clean dry toothbrush. See if better. If not, clean again with toothbrush and small amount of Isopropyl Alcohol. See if better. If not, try Restore. If still a problem, and there is Warranty or AppleCare make Genius reservation and take to Apple for resolution.

  • HT3775 Why won't a video clip play all the way through without stopping and loading so many times?

    Any video clip that comes via email will not play all the way through without stopping so many times to load that a short clip takes 10 minutes to watch.  Sometimes, the video simply stops and loads forever and ceases to work at all.
    This happens for Youtube videos also.
    I am using a Snow Leopard Imac.

    This happens for Youtube videos also.
    Uninstall the currently installed Flash plugin then reinstall new.
    Very important to uninstall the old first.
    Uninstall >  Troubleshoot Flash Player | Mac OS
    Then reinstall new from here >   http://get.adobe.com/flashplayer/
    Then restart your Mac.

  • Firefox crashed down many times (6-7) and doesn't open anymore giving me a warning sound each time i try to open it any suggestions?

    I'm using firefox (now 27b2) having many tabs opened and i got used to the fact that many times crashes down ... each time i restore the session and it starts again ... but yesterday it "died" on me. Each time i'm trying to run it i get a warning sound and firefox refuses to open. As far as i remember i didn't install any soft lately ... but right before it's death, my pc was getting frozen and need it reboot ... that happened 3-4 times and then firefox "left" this cruel world. I run S&D, Malware bytes, Avast IS ... found nothing. Tried to open it in safe mode unsuccesfuly getting the same warning sound. I decided to uninstall it (Revo uninstaller) and used Ccleaner to wipe the leftovers then i tried to reinstall it but when running setup i get a message says "File corrupt" and everything ends here. I tried firefox 26 stab and it worked like a charm but the question remains the same why the beta version refuses to run and/or to be reinstalled ... If there is someone out there (I'm sure there are many...) with any suggestions or advices i would be very grateful ...Thank you all...

    Hello,
    Certain Firefox problems can be solved by performing a ''Clean reinstall''. This means you remove Firefox program files and then reinstall Firefox. Please follow these steps:
    '''Note:''' You might want to print these steps or view them in another browser.
    #Download the latest Desktop version of Firefox from http://www.mozilla.org and save the setup file to your computer.
    #After the download finishes, close all Firefox windows (click Exit from the Firefox or File menu).
    #Delete the Firefox installation folder, which is located in one of these locations, by default:
    #*'''Windows:'''
    #**C:\Program Files\Mozilla Firefox
    #**C:\Program Files (x86)\Mozilla Firefox
    #*'''Mac:''' Delete Firefox from the Applications folder.
    #*'''Linux:''' If you installed Firefox with the distro-based package manager, you should use the same way to uninstall it - see [[Installing Firefox on Linux]]. If you downloaded and installed the binary package from the [http://www.mozilla.org/firefox#desktop Firefox download page], simply remove the folder ''firefox'' in your home directory.
    #Now, go ahead and reinstall Firefox:
    ##Double-click the downloaded installation file and go through the steps of the installation wizard.
    ##Once the wizard is finished, choose to directly open Firefox after clicking the Finish button.
    Please report back to see if this helped you!
    Thank you.
    <!-- VERY important to include-->
    <b>WARNING:</b> Do not run Firefox's uninstaller or use a third party remover as part of this process, because that could permanently delete your Firefox data, including but not limited to, extensions, cache, cookies, bookmarks, personal settings and saved passwords. <u>These cannot be recovered unless they have been backed up to an external device!</u>

  • When the message arrives, the message tone sound that many times. How this problem can be solved? I installed the new version, but the problem is not resolved, the future is to be taken into account in the new version of this?

    When the message arrives, the message tone sound that many times. How this problem can be solved? I installed the new version, but the problem is not resolved, the future is to be taken into account in the new version of this?

    I'm not sure I understand the question, is the message tone going more then once?
    Turn off repeat message alert here:
    settings > notifications > messages > repeat alert > never
    Some people have found this does not stop the repeat miessage tone,
    if you are one of those then I suggest you contact Apple:
    http://www.apple.com/feedback/iphone.html
    They may not respond, but hopefully will fix in uodate if enough people complain.

  • HT1415 You can move the rental between devices as many times as you wish during the rental period. However, the movie can only be played on one device at a time. If you rent a movie on an iPhone, iPad, iPod touch, or Apple TV, it is not transferable to an

    You can move the rental between devices as many times as you wish during the rental period. However, the movie can only be played on one device at a time. If you rent a movie on an iPhone, iPad, iPod touch, or Apple TV, it is not transferable to any other device and you must watch it on that device.
    This is a confusing statement. Can really move the rental between devices or not???  

    If you originally downloaded it to a computer, yes. If you originally downloaded it to an iOS device, probably not; if you want to try anyway, use the Transfer Purchases function in iTunes.
    (85739)

  • How can I stop a sound from looping so it plays only once each time the up key is pressed?

    Hi there here is my code, the basis is it is playing a mp3 from my library.
    Basically as the topic suggests I only want the sound to play once each time the UP arrow key is pressed. At the moment when you hold the up arrow down the sound keeps triggering and looping and gets really loud and noisy.
    Here is my code for my game:
    package com.chasegame.components
              import flash.display.MovieClip;
              import flash.display.Stage;
              import flash.events.Event;
              import com.tech.utils.KeyObject;
              import flash.ui.Keyboard;
              import flash.media.Sound;
              import flash.media.SoundChannel;
              public class SpaceShip extends MovieClip
                        private var key:KeyObject;
                        private var speed:Number = 0.3;
                        private var rotateSpeed:Number = 5;
                        private var vx:Number = 0;
                        private var vy:Number = 0;
                        private var friction:Number = 0.95;
                        private var shipSound:roar = new roar();
                        private var shipSoundChannel:SoundChannel = new SoundChannel();
                        public function SpaceShip () : void
                                            key = new KeyObject(stage);
                                            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
                        public function loop(e:Event) : void
                                            if (key.isDown(Keyboard.UP))
                                                           vy += Math.sin(degreesToRadians(rotation)) * speed;
                                                           vx += Math.cos(degreesToRadians(rotation)) * speed;
                                                           shipSoundChannel = shipSound.play();
                             else
                                                           vy *= friction;
                                                           vx *= friction;
                                  if (key.isDown(Keyboard.RIGHT))
                                            rotation += rotateSpeed;
                                  else if (key.isDown(Keyboard.LEFT))
                                            rotation -= rotateSpeed;
                                  y += vy;
                                  x += vx;
                                  if (x > stage.stageWidth)
                                            x = 0;
                                  else if (x < 0)
                                            x = stage.stageWidth;
                                  if (y > stage.stageHeight)
                                            y = 0;
                                  else if (y < 0)
                                            y = stage.stageHeight;
                        public function degreesToRadians(degrees:Number) : Number
                                  return degrees * Math.PI / 180;

    If you want the sound to only play once when the key is pressed then you don't want to have it in the ENTER_FRAME event handler like you have it.  It is starting new sounds at the frame rate of your file the way you have it now.
    Try having an event listener dedicated to a KeyboardEvent.KEY_DOWN event where you detect when the UP key gets pressed and use that to trigger playing the sound.

  • IPod classic displays 'No music' after sync, HDD problem? Geschiedenis • Verwijder  So recently I synced my iPod Classic 160 GB like I did so many times and when I wanted to play some music afterwards it couldn't find any files on the iPod anymore. H

    So recently I synced my iPod Classic 160 GB like I did so many times and when I wanted to play some music afterwards it couldn’t find any files on the iPod anymore. However when you look in the settings it displays that ~roughly 90 GB free space is available. Seen the fact that I had about 60 gigs of music this doesn’t seem like a coincidence and I think my music is still somewhere on the ipod but the HDD isn’t recognizing it anymore.
    I’ve tried resetting it, and resetting it to factory settings, which didn’t work. When connected to a desktop it won’t be recognized by iTunes, it displays an error message that the iPod cannot be read and that I have to reset it to factory settings.
    I’ve spent some time researching this problem yesterday and I ran into a myriad of vaguely similar problems didn’t really offer any help. Currently I’m thinking that formatting the iPod might work, and restoring the software afterwards. However this is a rather bold strategy so I’d like to consult you here first.
    Thanks in advance!

    Hi turingtest2,
    Thank you for the info, with formatting my iPod I managed to connect it to iTunes again.
    However..in the page you linked to there is a section about how transferring large amounts of data can dump your library. That seems to be the problem in this case. It won't even allow me to transfer more than 2 gigabytes of music per sync, if I go higher it will dump everything again. Having over >60 GB of music in my library, this is disastrous to say the least.
    Do you think that there is any other solution besides the method you mentioned involving Smart Playlists?

  • When i plug in my ipod to my PC it makes a sound like it doesnt accept it. on the ipod, it says connect to itunes because it was disabled many times. why wont it connect?P.S I know nothing about this kind of stuff

    when i plug in my ipod to my PC it makes a sound like it doesnt accept it. on the ipod, it says connect to itunes because it was disabled many times. why wont it connect?P.S I know nothing about this kind of stuff

    Disabled
    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                         
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: Back up and restore your iOS device with iCloud or iTunes       
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    If problem what happens or does not happen and when in the instructions? When you successfully get the iPod in recovery mode and connect to computer iTunes should say it found an iPod in recovery mode.

Maybe you are looking for