Loading and Playing Multiple Sounds

I have written a loadSound function which handles loading and playing multiple sounds. This function works fine when I call this function in another keyframe i.e. the frame in which the function is not written. But when I call the function on the same frame in which the function is written the sounds gets mixed up. For example the function is written in 1st keyframe. If I call this function in 2nd, 3rd and 4th keyframe (with different sounds) it works fine. But when i call the same function in 1st, 2nd and 3rd keyframe it all gets messed up.
In 1st keyframe the sound plays properly. When I move to 2nd Keyframe the 2nd sound plays. But when I move back to the 1st keyframe the 2nd and 1st keyframe sounds all get mixed up. This doesn't happen when I call the function in 2nd, 3rd and 4th keyframes.
Below is my function:
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.errors.IOError;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.media.SoundTransform;
stop();
var s:Sound;
var localSound:SoundChannel = new SoundChannel();
var req:URLRequest;
var loadedPct:uint;
var currentFrameArr:Array = ["One","Two","Three"];
var urlArr:Array = ["sound/m01_t01_s01.mp3","sound/m01_t01_s02.mp3","sound/page10_11.mp3"];
function loadSnd(currentFrm:String)
s = new Sound();
s.addEventListener(ProgressEvent.PROGRESS, onSoundProgress);
s.addEventListener(Event.COMPLETE, onSoundLoaded);
s.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
localSound.stop();
for (var i:uint=0; i<currentFrameArr.length; i++)
  if (currentFrm == currentFrameArr[i])
   req = new URLRequest(urlArr[i]);
s.load(req);
function onSoundProgress(evt:ProgressEvent):void
  loadedPct = Math.round(100 * (evt.bytesLoaded / evt.bytesTotal));
  trace("The sound is " + loadedPct + " % loaded");
function onSoundLoaded(evt:Event):void
  localSound = s.play();
function onIOError(evt:IOErrorEvent):void
  trace("The sound could not be loaded: " + evt.text);
Call to this function in different frames:
loadSnd("One");
loadSnd("Two");
etc
If I pass the parameter 'One' in loadSnd it plays the 1st element in urlArray, 'Two' 2nd element and so on.
I have been scratching my head since long over this.
Can anybody please pinpoint the error.

Got the solution. The SoundMixer.stopAll(); statement did the trick. The complete workable function is pasted below:
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.errors.IOError;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.media.SoundTransform;
stop();
var s:Sound;
var localSound:SoundChannel = new SoundChannel();
var req:URLRequest;
var loadedPct:uint;
var currentFrameArr:Array = ["One","Two","Three"];
var urlArr:Array = ["sound/m01_t01_s01.mp3","sound/m01_t01_s02.mp3","sound/page10_11.mp3"];
function loadSnd(currentFrm:String)
  s = new Sound();
  s.addEventListener(ProgressEvent.PROGRESS, onSoundProgress);
  s.addEventListener(Event.COMPLETE, onSoundLoaded);
  s.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
  SoundMixer.stopAll();
  localSound.stop();
  for (var i:uint=0; i<currentFrameArr.length; i++)
  if (currentFrm == currentFrameArr[i])
  req = new URLRequest(urlArr[i]);
  break;
  s.load(req);
function onSoundProgress(evt:ProgressEvent):void
  loadedPct = Math.round(100 * (evt.bytesLoaded / evt.bytesTotal));
  trace("The sound is " + loadedPct + " % loaded");
function onSoundLoaded(evt:Event):void
  localSound = s.play();
function onIOError(evt:IOErrorEvent):void
  trace("The sound could not be loaded: " + evt.text);
Calling the function
loadSnd("One");
loadSnd("Two"); etc

Similar Messages

  • 1120 error when attempting to load and play sounds

    I'm attempting to load and play a sound (which seems quite
    basic) but I am getting an 1120 error. Could anyone please help me
    figure out what I'm doing wrong?
    var hitSound:Sound = new Sound();
    var reqHitSound:URLRequest = new URLRequest("myAudio.mp3");
    hitSound.load(reqHitSound);
    hitSound.play();
    1120: Access of undefined property hitSound
    1120: Access of undefined property reqHitSound

    Yes, the mp3 is good and the path is correct. I'll put my
    complete code below.
    The error I get is:
    1120: Access of undefined property hitSound. (line 14 -
    hitSound.load(reqHitSound);)
    1120: Access of undefined property reqHitSound. (line 14 -
    hitSound.load(reqHitSound);)
    1120: Access of undefined property hitSound. (line 15 -
    hitSound.play();)
    Its almost like the code doesn't feel I've really defined
    hitSound as a Sound.
    Help please? Am I missing a component?

  • Lost the ability to play multiple sounds!

    Since switching to archlinux, the only problem that I am unable solve is the inablity to play multiple sounds.. i had this problem when i first installed archlinux. back then i tried installing pulseaudio and found that cumbersome. eventually went back to alsa and found magically i could play sounds at once..
    now again it has reoccurred ever since the module init tools upgrade. i have tried reconfiguring alsa with alsaconf with no avail.
    on trying to play sound file from the 2nd app i get a knotif saying
    The audio playback device HDA Intel (ALC880 Analog) does not work
    Falling back to .
    some of the conf files i have:
    [$]> grep MODULES /etc/rc.conf
    # MODULES: Modules to load at boot-up. Prefix with a ! to blacklist.
    # NOTE: Use of 'MOD_BLACKLIST' is deprecated. Please use ! in the MODULES array.
    MODULES=(e100 mii slhc snd-hda-intel snd-mixer-oss snd-pcm-oss snd-hwdep snd-page-alloc snd-pcm snd-timer snd soundcore !snd-pcsp)
    [$]> grep DAEMONS /etc/rc.conf
    # DAEMONS
    DAEMONS=(syslog-ng dbus @network netfs crond alsa hal cups @openntpd)
    [$]> cat /etc/modprobe.d/modprobe.conf
    # /etc/modprobe.d/modprobe.conf (for v2.6 kernels)
    [$]> cat /etc/modprobe.d/sound.conf
    alias snd-card-0 snd-hda-intel
    alias sound-slot-0 snd-hda-intel
    [$]> cat /etc/libao.conf
    default_driver=alsa10
    [$]> lspci | grep -i audio
    00:1b.0 Audio device: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) High Definition Audio Controller (rev 03)

    djszapi wrote:It seems to good. Did you try pulseaudio now too ?
    no i dont want to. it doesn't seem right with kde

  • Play multiple sounds

    Hello!
    How can I play multiple sounds at once please?
    I tried with 2 separate soundChannel vars but they still override eachother.
    Thanks

    play both sounds through the same sound channel? eg:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                private var sound:Sound;                       
                private var soundChannel:SoundChannel;   
                private function play1():void
                    sound = new Sound();
                    sound.load(new URLRequest("sounds/1.mp3"));
                    sound.addEventListener(Event.COMPLETE, songLoaded);
                private function play2():void
                    sound = new Sound();
                    sound.load(new URLRequest("sounds/2.mp3"));
                    sound.addEventListener(Event.COMPLETE, songLoaded);
                private function songLoaded(e:Event):void
                    try
                        sound.removeEventListener(Event.COMPLETE, songLoaded);   
                        soundChannel = sound.play(0);
                    catch(err:Error)
                        trace(err)
            ]]>
        </mx:Script>
        <mx:Button x="140" y="313" label="Play sound 1" click="play1()"/>
        <mx:Button x="229" y="326" label="Play sound 2" click="play2()"/>
    </mx:Application>

  • Installed Ensoniq AudioPCI SB32 - now I cannot play multiple sounds simultaneou

    I started with an el-cheapo on-board sound card (SiS 708). I just installed a Creative Ensoniq AudioPCI SB32 and can no longer play multiple sounds simultaneously.
    For example: if I am playing an MP3, WAV, or otherwise an audio file that uses the sound card's WAV output, other sounds such as the Windows event sounds or sounds assigned in my FTP application. I *could* do this without a problem using the SiS 708 card.
    More info:
    - I did leave the SiS 708 installed. Could this be conflicting?
    - I set the default I/O sound devices to the Creative Ensoniq in the control panel
    How can I play multiple simultaneous audio again?Message Edited by epp_b on 0-07-2006 07:48 PM

    I have tried the following things:
    - Uninstalling and disabling the onboard sound
    - Installing the latest version of DirectX
    I can't think of anything else (there are no updated Creative drivers that I can find)

  • Load and play different external MP3

    I wanted to do something I thought was simple - I wanted to have a sound playing (loaded external mp3) and then have various buttons on the screen that load an alternate song in its place.  Could someone please help me?
    This is what I'm trying to do:
    var myMusic:Sound = new Sound();
    var reqMyMusic:URLRequest = new URLRequest("mySong.mp3");
    myMusic.load(reqMyMusic);
    myMusic.play();
    music1_btn.addEventListener(MouseEvent.CLICK, music1);
    music2_btn.addEventListener(MouseEvent.CLICK, music2);
    function music1(event:Event)
        // LOAD AND PLAY A DIFFERENT MP3 (in place of mySong.mp3)
    function  music2(event:Event)
        // LOAD AND PLAY A DIFFERENT MP3 (in place of mySong.mp3)

    use:
    var myMusic:Sound = new Sound();
    var reqMyMusic:URLRequest = new URLRequest("mySong.mp3");
    myMusic.load(reqMyMusic);
    var sc:SoundChannel = myMusic.play();
    music1_btn.addEventListener(MouseEvent.CLICK, music1);
    music2_btn.addEventListener(MouseEvent.CLICK, music2);
    function music1(event:Event)
    sc.stop();
    myMusic = null;
    myMusic=newSound();
    myMusic.load(new URLRequest("whatever"));
    sc=myMusic.play();
    function  music2(event:Event)
    sc.stop();
    myMusic = null;
    myMusic=newSound();
    myMusic.load(new URLRequest("whatever"));
    sc=myMusic.play();

  • I have a iPhone 4S and when watching videos on the internet sound cuts out as the video is playing. The rest of the video plays with no sound. Sometimes when I pause It and play again sound comes back but not all the time. can anyone help?

    I have a iPhone 4S and when watching videos on the internet sound cuts out as the video is playing. The rest of the video plays with no sound. Sometimes when I pause It and play again sound comes back but not all the time. can anyone help?

    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.

  • Loading and Playing 2 videos at the same time

    Hello everyone
    I'm having a problem on loading and playing two videos at the same time on XletView.
    The background video, I'm loading by editing channels.xml that is located at config folder into xletview folder. I've just to add the file path and when i start the video it starts playing.
    But now, I have a problem. I have to load a file that is into my HD, and play it at the same time of the main(background) video.
    Do anyone know how to do this?

    anyone?
    PowerBook G4 1.67 GHz Mac OS X (10.4.7) 1.5 GB ram

  • Quicktime video (.mov file) will not load and play in Firefox 3.6.16

    I have a computer with Firefox 3.6.16 installed that will not play Quicktime videos (.mov files) in the browser. This is a desktop computer.
    Another computer (laptop) with exactly the same version of Firefox installed will load and play them perfectly in the Quicktime player.
    Both computers have Quicktime addin 7.6.9.0 installed and designated as the default application for Quicktime movies.
    Both computers play the videos correctly in IE 8.
    When attempting to play the video in Firefox, the player window opens and attempts to load the video, but soon seems to freeze leaving a black window open where the player should be.
    From what I have observed, this seems to be a problem related specifically to this computer, and since the video plays in IE I have ruled out the firewall blocking loading from the site.

    Hi, I've exactly the same problem, 'cept I've XP Pro. When I say exactly, I mean the format used is HDV 1080i60, along with everything else there.
    And I'm right there with you. Why Quicktime can't play a natively encoded HDV Quicktime file (using Final Cut Pro), is beyond me, but basically, I've used K-Lite Codec Pack, and Quicktime. Neither work, although Quicktime does ask for internet connectivity to download resources or something similar (I don't have Internet Access at home). I've used VLC on a friend's PC, and, while it works, there is a very strange, and irritating flicker where there's heavy movement
    Where can I get the resource needed, as another party needs to view the clip, and they already have it. So if they can update their codec library or similar, then that would be much better (as I wouldn't need to upload a FullHD Video again)
    thanks

  • Youtube videos not loading and playing on Mac Mini

    Safari can't stream videos from Youtube.  The videos may start to load and play for a few seconds to a minute, but I can't watch a single video all the way through without it continually pausing for minutes at a time, and then eventually just pausing indefinitely while the video tries to load.  I updated my Adobe Flashplayer plug-in (from Adobe's website), I reset Safari and emptied all of the internet info like cookies and things.  The mac is only a couple weeks old, so there's not a gazillion things added to Safari or anything like that, as far as extensions and plug-ins and whatnot.  I only have the "adblocker" extension, because it was recommended in a thread like this one, and had helped others with the youtube problem.  I'm not terribly computer savvy.  Please help! 

    From the menu bar, select
     ▹ System Preferences… ▹ Flash Player ▹ Advanced
    and click Delete All. Close the preference pane.
    From the Safari menu bar, select
    Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
    and confirm. Test.
    If you use a FireWire audio interface, disconnect it and test again.

  • Problem loading and playing samsung videos in elements

    Samsung videos will not play in elements

    hibernian
    No enough information to help you. Answers will be in the details.
    1. What version of Premiere Elements are you using and on what computer operating system is it running?
    2. What Samsung device is recording your videos that you want to edit in Premiere Elements?
    3. What are the properties of those videos, including video and audio compression, frame size, frame rate, variable frame rate, interlaced or progressive, file extension, and pixel aspect ratio?
    4. What are you or the program setting as the project preset to match the properties of your source media?
    5. Are you getting any error messages associated with "problem loading and playing samsung videos in elements"?
    6. Is there a problem loading and playing both video and audio or just video or just audio?
    Let us start here and then we can plan troubleshooting strategy.
    Thank you.
    ATR

  • Is there any way to load and play the iPad scrabble app on my Macbook?  i can't believe there is no scrabble app for my mac

    Is there any way to load and play the ipad scrabble app on my macbook?

    There hasn't been a Scrabble version for OS X since 10.3 -10.4 on PPC, the intel swtich and they just left.
    Scrabble owners will sue the living daylights out of anything that looks like it or uses the name.
    Would love to play on my new Mac latop
    Apple in their infinite wisdom didn't allow iOS apps to run/ported  as widgets etc on OS X Dashboard like many users requested long time ago.
    There is no Scrabble widget on Dashboard downloads page or anything close to it.

  • Flex 4.6 IOS Mobile packager - can it load and play swf's dynamically at run time?

    I have an app that shows the viewer slides in a SWFLoader object.  I load the slides at runtime from a remote server.  When I package the app for IOS using 4.6 the swf slides load and play fine in the IOS emulator on the PC.  They don't load, however, when I deploy to a provisioned iPad. 
    My guess is that IOS can handle doesn't know what to do with dynamically loaded swf data.  I'm not positive though because it plays in the emulator.  Is that emulator truly emulating xcode or is it running flash?
    Note:  this same app plays an rtmp flash stream just fine even on the device itself.  Just can't handle a dynamically loaded swf.

    The correct answer to this question appears to be that Apple's terms of service *do not* prohibit the loading of swf's on IOS from remote servers dynamically at runtime.  They prohibit the loading of swf's that *contain executable ActionScript code*. 
    I loaded a PPT into Adobe Connect and then retrieved the resultant slide swf's from the Connect server.  I took these swf's and loaded them into my iPad app, dynamically at runtime, from a remote server.  The swf's loaded and animations played.  I made no changes to my code.  I'm just using a plain old SWFLoader object.
    Loading swf's dynamically at runtime from remote servers into IOS works - if you make the swf's right.  How to do that I'm not sure.

  • Safari 8 does not properly load and play any mp4 video

    My Safari 8.0.3 on my OS X 10.10.2 does not actually load and play any MP4 video in-browser. All I see is the black loading bar.
    I have not installed any video codecs on my OS X, nor have I tinkered with any QuickTime settings.

    Perhaps a third parrty Safari add on that was compatible with the prior version of Safari but not 5.1 that's preventing pages to render as they should.
    Read here >  Safari: Unsupported third-party add-ons may cause Safari to unexpectedly quit or have performance issues

  • How do you play multiple sounds simultaneously and synchronized?

    lets say I have two wave files that are similar in play length but not quite the same. I calculate a new frame rate for reach to make their lengths almost perfectly the same. Now I want to play them and have them repeat for a while.. If I don't synchronize them in some fashion, inevitably the slight difference in play time will cause them to unsync.
    what's the best way to keep them in sync? I've been trying playing each sound in it's own thread for the past few days and using thread synchronization, but that isn't working so well.
    thanks for the help.

    I found the answer I'm looking for! version 1.5 came out with the CyclicBarrier class that causea a thread to pause when it calls the barriers await() function until a predetermined number of threads call await().
    So I can create a barrier of size (ThreadCount) and tell all threads to pause at the beginning of a measure until all threads have checked in. That way all threads are out the gate at the same time every measure.

Maybe you are looking for

  • Error while releasing transport request

    Hi, When i tried to release the transport request, it returning with code = 8 (error) so transport has not done. When I digged into the transport request, error message is 'unimplemented function REPC_OR_DELETE DOCUMENTATION'. Thanks in advance. Arvi

  • How can I see my iPhoto folders in apple tv?

    When I use the Apple TV, I cant see the folders I've created on my Iphoto. Instead of that the Apple tv shows my entire (12,500) pics database. Anyone know how to split that data out?

  • 0pen with Photoshop elements 10  dont load photos

    Hello, In Win7 ultimate when i try to open raw or jpg photos clicking on right key of the mouse "open with" Photoshop elements 10, the program start but never image is loaded. This issue is in Italy version. Please tell me is happen also in your vers

  • How do I run a thread without its panel.

    I have created a vi in my application that I run as a thread. I run the thread by using an invoke node. When I am testing under LabView everything is fine but when I create the executable I have found problems. As I am starting the thread with an inv

  • Renaming with firmware upgr

    i'm having trouble renaming songs with the new firmware update. It won't let me rename folders to the same thing so i have about ,000 artists from different CD's that have multiple artists on it but i want to rename all of them to the CD title for ea