Sound class

Hi everyone. I'm creating an audio player which will receive
xml information from a server and play the requested sone. I have
all that set up. The only problem I'm having with is creating the
progress bar while the sound is streaming. What happens is when the
audio player is opened, the song starts playing because of the
streaming property that I set in the actionscript, but the progress
bar doesn't show up until the song is fully cached on the user's
machine. So the effect is you don't see the progress bar when the
audio player opens and the song plays. Instead the progress bar
will appear a couple of seconds after the audio player starts
playing. I've put the project up on my site, so you can take a look
at it and see what I'm talking about,
www.mark-yieh.com/airspun/newaudioplayer.html. If you know how to
fix it please let me know. It will really be appreciated. Thanks.
I've looked at all the event handlers in the sound class, but none
of them let's me gather information from the sound file until it's
fully loaded. For example, with the MovieClipLoader class, there's
an onLoadInit handler and an onLoadStart handler and an
onLoadProgress handler, but there's none for the sound class. Is
there another solution?

if you're attempting to get the sound.duration before it has
loaded, then you'll find that this will only return the number of
seconds downloaded so far. sound.position should work okay though.
check out the comments in
livedocs
for sound duration for some handy ways to approximate this
property during streaming.

Similar Messages

  • Looking for information about AS3 sound classes in "audio" wrong places?

    I'm looking for in depth information about ActionScript 3.0 sound classes. No matter where I search I continually encounter the same sort of kindergarten level descriptions, which never teach more than what we can readily glean from Adobe's documentation. Someone must know where there a discussion that really gets to the heart of the matter.
    I've read Adobe's LiveDocs on the Sound, SoundChannel, SoundMixer, SoundTransform classes. Indeed, they provided me enough guidance to create my own streaming MP3 player, with volume, pan, my own custom mono mix, http request, a preloading animation, and peak meters ...
    Here's an example (in the last statement of the following code) where I understand the end effect, but I fail to comprehend what happens at the compiler level:
    var currentSoundSource:Sound = new Sound();
    currentSoundSource.load(new URLRequest("http://www.mySite.com/myRecording.mp3"));
    var audioChannel_01:SoundChannel = new SoundChannel();
    audioChannel_01 = currentSoundSource.play();
    Unfortunately the class definitions in LiveDocs are quite terse, and they're seemingly incomplete with respect to:
         •     advice on best practices
         •     a thorough coverage of class to class interactivity
         •     a description of exactly how audio streams/plays into channels
    ... and in certain cases it appears that Adobe's descriptions are not fully accurate.*
    Regarding best practices, at first blush I'm sure everyone ponders over the fact that SoundChannel and SoundMixer have a stop method while the Sound class does not.
    One assumes that this surprising design must bear some advantages. If so,  what are they? Where are the analog sound mixer analogies? What would be the disadvantage of a sound class with a stop method ...  particularly when they have their own play method?
    Where are the discussion of these concepts? (Even if Adobe hired the wrong guy to write its sound classes, there should be some follow through that thoroughly explains the existing situation.)
    Phrankie
    * Here's an instance where the docs appear to be partially in error. (Is "and play" mistakenly included in the following?)
    "The Sound class lets you lets you create a new Sound object [and] load and play an external MP3 file into that object."
    ... uh, mmmmmm ... we play an MP3 into a sound class object?
    Wouldn't it be more accurate to say the following:
    A soundChannel can receive the audio data from a sound class object. We can play a sound object into an SoundChannel and manipulate it by altering the SoundChannel's soundTransform property, and we can stop it with the SoundChannel's stop method. 

    check everything you can find written by tinic uro.  this will get you started:  http://www.kaourantin.net/

  • About playing dynamic generated sound using Sound class

    Dear sir:
    The live doc of Flex 4 says:
    In Flash Player 10 and later and AIR 1.5 and later, you can also use this    class to work with sound that is generated dynamically.    In this case, the Sound object uses the function you assign to a sampleData event handler to   poll for sound data. The sound is played as it is retrieved from a ByteArray object that   you populate with sound data.
    and i read one article(the following link)
    http://www.kaourantin.net/2008/05/adobe-is-making-some-noise-part-2.html
    it said: The Sound class only support 44100 sample rate,32 bit,2 channel sound data, is that true?
    Then if i get one ByteArray( 8000 sample rate,16bit,1 channel), how can i modify it to let the Sound class play it?
    thanks..

    Worked perfectly.  Thank you thank you!
    Jen

  • Sound class pause

    Hi i have a flash presentation, which has a pause and play
    button.
    the pause button pauses my movie fine, except i have voice
    sound as a sound class, the sound starts to play, but i can not get
    it to pause or stop
    any ideas what i need to do?
    i have the following code

    no, your code above is not correct: your onRelease functions
    are written as such to be placed directly on your button objects
    and not on the root time line; additionally, the function
    volAdjust(), which is the function responsible for controlling your
    sound, is not present in your code at all.
    to fully understand what is going on, take five minutes to do
    this:
    1.) open a brand new flash document.
    2.) import a sound to your library ( file > import >
    import to library ), open your
    library ( f11), right-click on the sound inside your library
    and select linkage,
    check export for actionscript, make sure export in first
    frame is checked, and
    then enter, newWelcome , into the identifier text field.
    3.) draw a rectangle on stage and convert it to a movieclip
    (f8) - name it whatever you wish.
    4.) with the newly created movieclip selected, go to your
    properties inspector
    and enter the string, btnPlay , into the instance name text
    field.
    5.) open your library ( f11) and drag another instance of the
    movieclip you just
    created onto the stage.
    6.) with the newly dragged out instance of your movieclip
    selected, go to your
    properties inspector and enter the string, btnPause , into
    the instance name text field.
    7.) make a new layer above the one you have working in and
    name it actions.
    8.) lastly ,copy and paste the code i sent you into the first
    frame of the layer
    actions. (note: your movieclips, btnPlay and btnPause,
    should be on the first
    frame of your second layer ( the layer beneath your layer
    labeled actions ).

  • Why Sound Class is greyed out?

    Hi, there
    I am trying to assign a sound class, but found it was greyed out. I'd appreciate if someone could help me to find a way...Thanks!

    I think you're right. The file I was working on was originally in AS2...Thanks a lot!

  • Sound class help?(oop)

    hey,
    i have got all my public vars for sound class but im having trouble on how i would execute them because i normal would use event listener but its OOP lol so how do you get that functionality :/
    ---code in star.as file:
    package
        import flash.display.MovieClip;
        public class star extends MovieClip
            public var my_sound:MySong = new MySong();
            public var my_channel:SoundChannel = new SoundChannel();
            public function star()
    thanks everyone

    dont worry i learnt oop and made my own class here it is if anyone has the same problem!
    Code:
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.media.Sound;
        public class SoundClass extends MovieClip
            var sound = new Sound  ;
            var mySound:MySong = new MySong  ;
            public function SoundClass()
                mySound.play();
    Hope this helped somebody else

  • Performance problems with external sounds and Sound class

    I'm using Sound & SoundChannel classes to load and play external MP3s and I'm seeing terrible playback performance on my 3G phone. Audio starts out ok, but will gradually get more and more choppy and eventually crashes the app. The MP3s themselves are typical sizes, 2 - 6 MB and of various types (VBR, CBR).
    On top of that, when the phone gets locked (with the app still running), the audio sputters and stops completely. When I unlock, it begins where it left off. Anyone else seeing this?
    My code is pretty standard:
    private var soundPlayer:Sound;
    private var soundChannel:SoundChannel;
    public function load(url:String, playNow:Boolean = true):void {
      if (soundChannel) {
        soundChannel.stop();
      soundPlayer = new Sound();
      soundPlayer.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
      soundPlayer.addEventListener(ProgressEvent.PROGRESS, onProgress);
      soundPlayer.addEventListener(Event.ID3, onID3);
      trace('Loading new stream: '+url);
      var request:URLRequest = new URLRequest(url);
      soundPlayer.load(request);
      if (playNow) {
        this.isPlaying = true;
        soundChannel = soundPlayer.play();
        soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);

    this is from another forum (http://discussions.info.apple.com/thread.jspa?threadID=2542931&tstart=0&messageID=12106188 ):
    "I've spoken to the developers of of couple of these apps, and they've all said it's a memory fragmentation/low memory condition.
    Restart the phone. Don't just turn it off and on, but restart it.
    Hold the on/off button and the home button down like you were going to turn it off. When you see the swipe to turn off message, keep holding the buttons down.
    In a few seconds the screen will flash, and then go dark.
    Now it's really off.
    Turn it back on (restarting it). All should be well.
    The iPhone is really a computer. Performing a restart like this every  once in a while (weekly, bi-weekly) is a good idea, esp if you use  memory intensive apps."
    coop

  • Automatically generated (Sound) classes

    Hi all,
    Quick summary:
    I'm trying to compile a SWC file with a lot of assets in it in an as easy possible way. "Easy" for a not so technical end user, not perse the way to acchieve that goal. Goal is to streamline a process to generate SWC files with as little possible tech for the person doing it.
    So, sort of like  manually doing:
    * Import files into Flash
    * For each library item select "Export for actionscript" and have Flash generate the basic class.
    * Publish as SWC
    but without the Flash IDE and the possibly labourous process.
    Right now I'm trying to put an AIR project together that generates classes based on a file list. The classes can than be added to a Flash Builder library project to generate a SWC file from it (copy in finder, check classes in Project properties, done)
    I can generate the classes for graphics like below. Such a class can then be instantiated from within the host application.
    package
              import flash.display.Bitmap;
              import flash.display.MovieClip;
              public class __0038_asset extends MovieClip
                        [Embed(source="assets/__0038_asset.png")]
                            private static const gfx:Class;
                        public function __0038_asset()
                                  super();
                                  addChild( new gfx() as Bitmap );
    Allthough this adds another level to the display list (which looks kinda sloppy to me), it works.
    However, for this to work for sound files I need to create a class implementing all possible methods and properties of the soundclass and handle the events and such. There is no way to extend Sound and then do something like you would/can with graphics.
    This is what I got:
    package
              import flash.media.Sound;
              import flash.media.SoundLoaderContext;
              import flash.net.URLRequest;
              public class _000_cover_hotsp_authormp3 extends Sound
                        [Embed(source="assets/000_cover_hotsp_author.mp3")]
                        private var snd:Class;
                        public function _000_cover_hotsp_authormp3(stream:URLRequest=null, context:SoundLoaderContext=null)
                                  super(stream, context);
                                  var mySound:Sound = new snd() as Sound;
    But that aint gonna work ofcourse.
    Does anyone know if there is a way to get to the format the Flash IDE generates the classes with?
    Thanks in advance.
    Manno

    Wel, here's the answer. Must have read it once since it is in the moock book, but stubled across it on the interwebs at: http://blog.nightspade.com/2010/02/01/embedding-asset-at-compile-time-in-pure-as3-project/
    For images use:
            [Embed(source="assets/Frog&Stranger02_03-titelblad_height_1024px 2.jpg")]
              public class a_A2BA79B5_CE46_F942_1AB2_CC26D8F7FCC8 extends Bitmap
                        public function a_A2BA79B5_CE46_F942_1AB2_CC26D8F7FCC8()
                                  super();
    and for sounds:
              [Embed(source="assets/000_cover_hotsp_author.mp3")]
              public class _000_cover_hotsp_authormp3 extends Sound
                        public function _000_cover_hotsp_authormp3()
    Now, lets review some code to see if I can apply this elsewhere too

  • Sound Class in AS3

    I am still learning AS3, and I was woking with sounds. This
    was to be used to stop the cound assigned to the channel1 var. When
    I click the button the sound is just muffeled a bit, but does not
    stop playing. Does anyone know it there is an issue with flash
    running in Windows Vista?
    Here is the code:
    //Stop Function
    function stopClick(evt:Event):void{
    channel1.stop();
    bStop.addEventListener(MouseEvent.CLICK, stopClick);
    Thanks

    I figured it out. When I added the soundLoaded function, I
    thought I deleted the .play() and head of my code. Now it looks
    like this, and works.
    //Creates a var musicURL and assigns it the background
    music.mp3 location name
    var musicURL:URLRequest = new URLRequest("background
    music.mp3");
    //Creates a var sndMusic and points it to the musicURL
    location
    var sndMusic:Sound = new Sound(musicURL);
    //Creates a SoundChannel var
    var channel1:SoundChannel;
    //Plays the sndMusic and assigns the soundChannel to channel1
    function errorMsg(evt:IOErrorEvent):void {
    trace("The sound could not be loaded");
    sndMusic.addEventListener(IOErrorEvent.IO_ERROR, errorMsg);
    function soundLoaded(evt:Event):void {
    trace("Sound Complete");
    //Plays the sndMusic and assigns the soundChannel to
    channel1
    channel1=sndMusic.play();
    sndMusic.addEventListener(Event.COMPLETE, soundLoaded);
    //Stop Function
    function stopClick(evt:Event):void{
    channel1.stop();
    bStop.addEventListener(MouseEvent.CLICK, stopClick);
    //Start Function
    function playMusicClick(evt:Event):void{
    channel1.stop();
    channel1=sndMusic.play();
    bPlayMusic.addEventListener(MouseEvent.CLICK,
    playMusicClick);
    Thanks. I hope this will be useful for who ever else make the
    same mistake I did.

  • Basic Sound Class

    I'm am busy creating a simple game. I want the user to be able to play wav files while the game is running. Could someone possible point me to a very basic Class that plays wav files. Basically i want to be able to create a new instance of this class and send it the filename, and it must then play the file. Try as i might, JavaSound just confuses me.
    thanks.

    have you seen this?
    [url http://www.jsresources.org/examples/SimpleAudioPlayer.java.html]sample
    sourcecode sample / demo

  • About Sound Class, play stream Intermittent

    such as ,I write a flash MP3 stream player,that can play
    network mp3, and Internet broadcast.
    but after i hear a advertisement , it's should play mp3
    songs,however now it's Intermittent.
    it's strange , the advertisement also a mp3 steam, but never
    be intermittent,once play song it's intermittent.
    I have tested, it's not the network speed case.
    I saw a player use AS2, it's ok, but I rewrite it with AS3,
    this problem is appeared.
    IT'S AS3 BUG?

    My example is this. Do you have this issue?
    http://www.namipan.com/d/034e9f09711dbf18a8583eb72fc31ec91a23d5eb33800300
    Is anyone kown, many thanks

  • I need to get sound events from sounds embedded in a MovieClip

    I'm working on a SoundManager class for a game development
    platform. Unfortunately, I can't leverage the Sound class because
    the requirements are that the sounds for an application would be
    embedded in individual MovieClip objects and set to stream as the
    clip plays.
    The idea is that this would allow third-party developers to
    make simple edits to the sounds by using the envelope controls for
    the embedded sounds. I can manually fire an event when the sound
    finishes by calling a custom method in the last frame of the movie
    clip, however, this is not completely accurate and it makes it
    impossible to seamlessly loop sounds.
    Now, the Flash player must be aware that the sound has
    finished playing. I presume that sounds embedded in the IDE are
    handled by the Sound class in some way. Is there any way at all
    that I can expose an event when the embedded sound finishes
    playing?
    I'd really prefer to use another approach, and just attach
    sound files from a Library or from external files, but I don't have
    a choice in this particular case. This is the way the application
    has to work.
    I will probably have to give up on the precision I want in
    order to complete this job on time, but I refuse to believe that
    what I'm trying to do is impossible. I would appreciate any help
    anyone can give me.

    You'll have to update your OS on your Macbook.
    Click on the black Apple logo at the top left of your Mac screen.  Then click on Software Update.
    support.apple.com/kb/ht1338

  • How do I get a handle on embedded sound files?

    From the Sound Class information, it says to use the SoundMixer Class to handle embedded Sound Files.  I have two sound files embedded, that I have setup in 2 separate layers, starting at frame one in the main timeline.  I needed to do this so I could see the wave files, and coordinate text with the waves.  I do not want to load these files into the .swf file at runtime using URLRequest.  How do I get a handle on those as they exist, to make each controllable by separate volume and mute controls for each sound?
    This will be a challenging question, because, "it can't be done" doesn't work for me.  I managed to create a way to use an external classfile to control the main timeline, the ROOT timeline, without having to create a sub movie to root.  I can use my component to call play(); as though it were in code in a frame.  But it isn't, it's in an external classfile.  I passed root to the classfile and told the classfile to think of it as a movieclip - that put the handle on it.  I tried similar way with root as a Sound, but that isn't detailed enough - I need to get a handle on the frame that contains the embedded sound file.  I embedded, attached it, using the properties view for the frame.
    I've attached, or whatever you want to call it, these sound files to a frame, and this frame is or should be attached to the layer I've created.  So, under the assumption that the ROOT has everything attached to it in some manner (it is after all the foundation for the COM), the stage of the root contains the visual components, so ROOT has to have the layer objects attached to it, which should have the frame objects attached to the layers.  I have two layers that each have a .wav file attached to frame one.  Somehow Flash keeps track of that - I want to know how Flash does it so I can read what flash reads.
    If this seems redundant, it probably is.  I want to paint the best picture I know how so I can get detailed feedback.  Please, if you have questions ask them so we can clarify, and get this resolved!  Thanks for reading!

    lol.
    ok, it can be done.  keep working on it.

  • Out of memmory with Sound object

    Hello,
    I have 2k+ of mp3 files and i need form playlist based on id3 tags. When i create air.Sound object in JS I run load() method and get ID3 tags in COMPLETE event handler. After that i create new Sound object for next file and all looks fine but near 900 file I get Out of memmory error. Whats wrong?
    Before create new object I set old variable value to NULL.

    Below is my basic code. I can convert it into something even more bare if needed. Basically I scan the hard drive for mp3 and AAC's, then pass the file object to this class to get the id3 tags. I've tried deleting sound, setting it to null, but no matter what I seem to have the song sticking in memory. It seems to be about 8MB of RAM for each sound object opened.
    NX.Sound = Class.create(,
         getId3Object: function(file, onComplete){
              var urlRequest = new air.URLRequest(file.url);                    
              var soundLoaderContext = new air.SoundLoaderContext(0, false);     
              var sound = new air.Sound();
              sound.addEventListener(air.Event.ID3, function(e){           
                var id3 = air.Sound(e.currentTarget).id3;
                id3.path = file.url;
                id3.title = id3.TIT2;
                id3.artist = id3.TPE1;
                sound.close();
                      onComplete(id3);
              sound.load(urlRequest, soundLoaderContext);

  • AS3 Sound Problem...

    It's pretty simple really. I'm loading an swf into another.
    The child swf is playing audio. But when I remove it ( using
    removeChildAt( 0 ) ) , the sound keeps playing. I can't get it to
    stop. Everything else is gone. Just not the music.
    I'm sure it's something easy. It always is.
    Thank you in advance for any help.

    Are you coding your sound utility in a separate package/class
    or is it inside your fla? Either way, sound like you just need to
    terminate the sound prior to removing the DisplayObject containing
    the sound. I believe the sound class has it's own set of rules that
    don't follow those that the rest of the display object classes do.
    You'll need to look at the help for more information but I've
    always killed all my sounds before killing the parent clip.

Maybe you are looking for

  • Boot Camp / Windows Partion... Can it be installed on a separate hard drive

    I am just beginning to explore the idea of installing Boot Camp & Windows on a new Intel Mac I will be buying. I've been reading a lot of references to the Windows partition... Can I dedicate a separate hard drive to Windows rather than partition my

  • Apple Service in Asia

    I have un-present feeling with your Apple Care Center service. It’s stared with your front line staff Ms. Winnie Tang Apple Care Center (SN). I have purchased an iMac Intel 24’ though the Apple on line store on August 8, 2007 and received the unit on

  • Img tag in RichTextEditor Adobe AIR

    Hi, I wanted to insert an image into a RichTextEditor in AIR application. For my surprise I found this code working perfectly if the project was Web application but it doesn't work if I use it into AIR Desktop application. Here's the code      <mx:Ri

  • Using ModelSupport2.dll in LabView without TestStand

    I would like to use the ModelSupport2.dll purely in a LabVIEW environment as either by a "Call Library Function Node" or "Active X" or ".NET" without using TestStand. In particular I would utilize the the "DisplayPassBanner" and "DisplayFailBanner" f

  • Non Printing Template Background

    Hello, I have a pdf form that I wish to use as a template. The problem is that the form is already printed and all I want to print is the field data, omitting the background template from printing over the form. How can I do this? It seems as though