SoundChannel position

Why isn't the end position of a sound channel the same as the length of a sound?
        public function play():void
            soundChannel = sound.play();
            soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
        private function onSoundComplete(e:Event):void
            var endPosition:Number = soundChannel.position;
            var length:Number = sound.length;
If you test the previous code you will see that the position of the soundChannel when SOUND_COMPLETE is dispatched is different then the length of the sound.
Why isn't the soundChannel play all the sound? Why does it stops earlier? and how can I find the end position of the soundChannel without playing and listening to the SOUND_COMPLETE event?

imnikey,
I see no one has answered your question.  I don't have an answer either, but I'm experiencing similar problems with the SoundChannel position. The problem with tracking the sound object's position through its sound channel gets worse when there is more than one Flash movieclip open in a different browser window.  Opening a Flash audio player seems to work fine if it is the only Flash movieclip open on my desktop.  After I open another Flash object in a separate window, the audio player fails to properly track the SoundChannel position, and fails to correctly fire the SoundComplete event.
Anyone else experiencing these problems?  Has anyone been able to find a reliable method for tracking the sound channel position with more than one Flash movieclip open on the desktop?  Is this a known issue or bug with the Sound API for Flash Player 10?  We could really use some answers.
jazzsurfer

Similar Messages

  • [AS3.0]SoundChannel.position≠Sound.length

    別の掲示板の引用で恐縮ですが、まさにこの問題に直面しています。
    http://www.flash-jp.com/modules/newbb/viewtopic.php?topic_id=7819&forum=8&post_id=38874#f orumpost38874
    上記サイトで書かれていますが、
    「 Firefox 2.0.0.14 & Internet Explorer 7.0/Windows Vistaで確認したところ、SoundChannel.positionプロパティの値がSound.lengthの値に達しないという問題が生じました。」
    の問題に対する、解決策、回避策などはございませんでしょうか。
    AS3.0+Vistaの環境では、mp3の再生に合わせてバーを伸縮させるスライダーようなものは作れない、なんてことはないと思うのですが・・・
    再生終了時のpositionの値がlengthの値と同じにならなくても、その終了した時の値が、再生前に分かれば問題ないのだと思うのですが、そのようなことは無理でしょうか。
    その他、何か情報がありましたら、ぜひよろしくお願いいたします。

    Thanks Andrei.
    But I really dont understand. You see, I am not too good (actually pretty bad) with Ationscript 3.
    Att.,
    Edwin
    I managed to get it to move each second though with this:
    var myTimer:Timer = new Timer(1000);
    myTimer.addEventListener(TimerEvent.TIMER, runTimer);
    myTimer.start();
    function runTimer(event:TimerEvent):void {
    trace("Hello");
    progreso.value = progreso.value+1;

  • SoundChannel.position inaccuracies within SampleDataEvent.SAMPLE_DATA

    The application generates sound dynamically by handling SampleDataEvent. It needs to determine exactly what part of the sound was actually playing when a click was made.
    Unfortunately, the latency calculation is slightly off because SoundChannel.position seems to be returning values that are +- 20 milliseconds off. The attached class demonstrates the issue by using a timer to occasionally check the position against the current time, displaying the difference between the two, along with the range of differences over time. The timer fires as often as it can so different ranges can be seen by using different movie frame rates.
    I'm not sure why this is, but I'm guessing it's something to do with the fact that the sound buffering is happening in a separate thread. Perhaps this thread only periodically updates the main thread about its position?
    Is there any more accurate way to calculate latency? Or maybe some way to know just how much the position value with be off at any given time?

    The application generates sound dynamically by handling SampleDataEvent. It needs to determine exactly what part of the sound was actually playing when a click was made.
    Unfortunately, the latency calculation is slightly off because SoundChannel.position seems to be returning values that are +- 20 milliseconds off. The attached class demonstrates the issue by using a timer to occasionally check the position against the current time, displaying the difference between the two, along with the range of differences over time. The timer fires as often as it can so different ranges can be seen by using different movie frame rates.
    I'm not sure why this is, but I'm guessing it's something to do with the fact that the sound buffering is happening in a separate thread. Perhaps this thread only periodically updates the main thread about its position?
    Is there any more accurate way to calculate latency? Or maybe some way to know just how much the position value with be off at any given time?

  • SoundChannel.position won't reset

    I'm trying to play an audio that goes along with the text on the screen.  As the audio plays, a timer event handler checks the SoundChannel.position to see determine what text should be highlighted. In my application I have a few audios that play in succession.  When one ends, the SoudComplete event is fired and I start playing the next audio.  I create a new sound object and reset the timer, but for some reason, the SoundChannel.Postion is off.  Here is my code:
    private function soundComplete(evt:Event):void
    //unHighlightSegment(this.curSegment_int);
    //timer.removeEventListener(TimerEvent.TIMER, highlightNext);
    //timer.stop();
    oSoundChannel.removeEventListener(Event.SOUND_COMPLETE, soundComplete);
    /*oSoundChannel = null;
    oSound = null;*/
    //timer.reset();
    if(this.toggleFull_bl && (curSegment_int+1 < this.dialogueText_ary.length))
    if(this.normal)
    playAllNormal(curSegment_int+1);
    else
    playAllSlow(curSegment_int+1);
    return;
    dialoguePlaying = false;
    firstPlay = true;
    isPaused = false;
    stopPlaying();
    playDialogue_btn.gotoAndStop("playUp");
    //plays the entire audio
    private function playAllNormal(seg:uint):void
    //trace(audiosToPlay_ary[curDialogue_uint] + "_nml.mp3");
    //soundEnd = true;
    timer.stop();
    timer.reset();
    timer.removeEventListener(TimerEvent.TIMER, stopVocalPlayback);
    timer.removeEventListener(TimerEvent.TIMER, highlightNext);
    trace("playAllNormal", seg);
    try
    trace("stop audio");
    oSoundChannel.stop();
    catch(e:Error)
    trace("Sound Channel object not yet created");
    var temp:int = dialogInfo.Segment[seg].Dialog;
    trace(String("CurrentDialog"), temp);
    oSound = new Sound(new URLRequest(audiosToPlay_ary[temp] + "_nml.mp3"));  //Create a new sound
    oSoundChannel = oSound.play(uint(audioTimes[temp].Time[dialogInfo.Segment[seg].Seg]));  //Play the sound and assign this to oSoundChannel
    trace(audiosToPlay_ary[temp] + "_nml.mp3", audioTimes[temp].Time[dialogInfo.Segment[seg].Seg]);
    oSoundChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
    oSoundTransform.volume = volumeLevel;
    oSoundChannel.soundTransform = oSoundTransform;
    trace("Sound position just after play", oSoundChannel.position);  //oSoundChannel.position should be close to zero here.
    timer.addEventListener(TimerEvent.TIMER, highlightNext);      //add the timer event to check the soundchannel position
    timer.start();
    private function highlightNext(evt:TimerEvent):void
    var len:uint;
    len = this.dialogueText_ary.length;
    if(normal)
    if(curSegment_int+1 < len)
    if(oSoundChannel.position >= uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].Time[dialogInfo.Segment[curSeg ment_int].Seg]) && oSoundChannel.position < uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].Time[dialogInfo.Segment[curSeg ment_int].Seg+1]))
    highlightSegment(curSegment_int);
    var a:int = 1;
    else  //if the position is not within range, highlight the next segment and increment the curSement counter
    unHighlightSegment(curSegment_int);
    curSegment_int++;
    trace("highlightNext", curSegment_int, oSoundChannel.position);
    else if(curSegment_int+1 == len)
    highlightSegment(curSegment_int);
    else
    if(curSegment_int+1 < len)
    if(oSoundChannel.position >= uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].TimeSlw[dialogInfo.Segment[cur Segment_int].Seg]) && oSoundChannel.position < uint(audioTimes[dialogInfo.Segment[curSegment_int].Dialog].TimeSlw[dialogInfo.Segment[cur Segment_int].Seg+1]))
    highlightSegment(curSegment_int);
    else
    unHighlightSegment(curSegment_int);
    curSegment_int++;
    else if(curSegment_int+1 == len)
    highlightSegment(curSegment_int);
    here's the output I get:
    JAN_2000_Claudia1_TYE_Cesar_1.1_nml.mp3 42440
    Sound position just after play 42440
    highlightNext 16 45458.59410430839
    highlightNext 17 47687.70975056689
    highlightNext 18 47780.589569161
    highlightNext 19 47873.4693877551
    highlightNext 20 47919.90929705215
    highlightNext 21 48059.229024943306
    highlightNext 22 48152.10884353741
    highlightNext 23 48244.988662131516
    highlightNext 24 48337.86848072562
    highlightNext 25 48430.748299319726
    highlightNext 26 48523.62811791383
    highlightNext 27 48570.06802721088
    highlightNext 28 48662.947845804985
    highlightNext 29 48802.26757369615
    highlightNext 30 48895.14739229025
    highlightNext 31 48941.5873015873
    playAllNormal 32
    stop audio
    CurrentDialog 1
    JAN_2000_Claudia1_TYE_Cesar_1.2_nml.mp3 35015      -- This is where things go wrong
    Sound position just after play 35014.988662131516          --sound position should be zero here.  Because it's not zero, the position is out of range 
    highlightNext 32 35061.42857142857                               --and the curSegment counter is incremented and the highlighted segment skips ahead too
    highlightNext 33 36315.30612244898                               --far
    highlightNext 34 38962.380952380954
    highlightNext 35 39055.26077097505
    highlightNext 36 39101.70068027211
    highlightNext 37 39194.58049886621
    highlightNext 38 39241.02040816326
    highlightNext 39 39380.34013605442
    highlightNext 40 39426.78004535147
    highlightNext 41 39519.65986394558
    highlightNext 42 39566.099773242626
    highlightNext 43 39705.41950113379
    highlightNext 44 39798.29931972789
    highlightNext 45 39844.73922902494
    playAllNormal 46
    stop audio
    CurrentDialog 2
    JAN_2000_Claudia1_TYE_Cesar_1.3_nml.mp3 28812
    Sound position just after play 28811.995464852607          --again here the position should be 0
    highlightNext 46 28858.43537414966
    Any ideas on why the position is not close to zero just after I begin playing?

    Somewhere between the sound ending and the firing of the soundComplete event, the timer still keeps counting and firing the timer event.  Any suggestions on how to stop the timer?  I already call Timer.stop() and Timer.RemoveEventListener when the sound complete fires, but the timer still has time to fire several times before I can stop it in the SoundComplete event handler.

  • Trouble Understanding variables

    I am committed to learning A3, but HOLY CRAP!! I have never
    been a programmer, just a lowly designer. Apparently a pretty dumb
    designer! :)
    I can breeze through this in AS2 with no problem, but AS3 is
    killin' me! I am trying to create a music player that will embed in
    a web page, it will be XML driven and the XML will be populated via
    a database and generated by PHP. I am using a listbox component to
    display the playlist (from the XMLfile). I have figured out how to
    start playing the first mp3 on the list.
    Now when the user click a different button, I can get that
    song to play also, but I ended up created a second sound object, so
    the two play at the same time. Not good. I have tried and tried to
    access the object that is playing the first sound so I can stop it
    and load a new sound into it - I am about to pull my hair out!
    I seem to missing a basic understanding of how to access this
    object and change the variable value so I can play a new song. Any
    help would be GREATLY appreciated!!

    Vern,
    > If I understand correctly: any variable I am going to
    use outside
    > of the function that assigns its value needs to be
    declared OUTSIDE
    > of that function first?
    Yes.
    > Once declared it can be used anywhere, but if it isn't
    declared
    > outside, then the value is stuck inside that function.
    Is that correct?
    Close. In fact, if you're coding in the main timeline,
    you're so close,
    you could arguably define it in those terms and be fine.
    Variables (and
    functions) are available to the scope in which they're
    declared. If you
    declare a variable in the main timeline, then that variable
    is available in
    that frame and any subsequent frame of that timeline.
    Depending on the
    circumstances of your FLA, the main timeline may indeed feel
    like
    "everywhere," to the point where the variable could be said
    to be used
    "anywhere" -- but it's really not much different from the
    restriction a
    variable feels when declared inside a function; it's just
    that the whole
    movie takes place inside that "function"/FLA/SWF.
    > If I got that right, then for my scrubber, I need to set
    up some
    > variables that hold SoundChannel.position, Sound.length,
    > MovieClip.position
    > THEN create a function which assigns values and
    calculate the
    > MovieClip.position
    Yes. That way, any number of functions can use those
    variables. But
    keep in mind, all you really need are variables that point to
    your instances
    of Sound, SoundChannel, and MovieClip. Then use those
    variables to
    reference the necessary properties of those classes. (In
    other words, no
    need to make a mySound variable *and* a mySoundLength
    variable: the mySound
    variable suffices, because it leads to the Sound.length
    property as simply
    as mySound.length.)
    > I never liked how clunky onEnterFrame could is. I assume
    the Timer
    > class is a bit more streamlined?
    It's just another tool in the toolbox. :) Timer is the
    recommended new
    version of setInterval() and setTimeout() combined.
    > I am so used to _root.movieClip.variable=foo; (I mean
    the easy
    > access to any variable from anywhere) but change is
    good, I like
    > change. Change is good.
    I like change in my pocket! ;) The thing about an expression
    like
    _root.movieClip.variable is that you could often just
    reference the variable
    anyway, without the need for the "_root" reference. AS3 has
    root (no
    underscore), which behaves in many ways like _root, but dig
    into that a bit
    ... you'll find some important differences.
    > So it sounds as if, to include the loadbar within all of
    this, then I need
    > to move the playHead along the width of the loadbar, not
    a set length
    > in pixels.
    You could do a set length, but it's much more flexible if
    you use the
    width of some other object, like a track or some other movie
    clip. If you
    go with the width of some object, you can *change* the width
    of that object
    and the code still works.
    > The drag part should be easy enough, but adjusting the
    actual audio
    > from that may give some fits!
    To derive volume, you'll take the position of the draggable
    knob along
    its track and divide that by the width of the track. Assume
    you have a
    ridiculously long volume track, 500px. The volume knob has
    been dragged
    halfway across, to 250px. 250 / 500 is 0.5, which is the AS3
    way of
    specifying 50% volume. Now imagine the track is 50px wide.
    The knob has
    been dragged all the way across (to 50px). 50 / 50 is 1,
    which is 100%
    volume. And so on.
    > But here is my real question about that, will it be OK
    to try and add
    > that functionality in once the actual playHead is
    working, or is
    > that a mistake to not include it from the beginning?
    Ehh, for something like this -- especially if you're
    teaching yourself
    and involved in a learning experience -- I'd say it doesn't
    matter one way
    or the other. Take small steps and master each step. Sooner
    or later, what
    you're doing will "click" for you, and after that, you'll
    find that you can
    add or remove features as you please.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Function to change mp3 and frame (video)

    I am currently working on a music site that has a custom built mp3 player, where the action script calls to an external xml. It works beautifully. It is all on one frame.... in the background of the music player is edited video that I manipulate in final cut. I have next  and pre buttons that call the xml. What I am trying to do is change the video when the song is changed. Im not sure if I call a fuction to the button next frame + or - 1 or if I can call the video to the xml. I am a graphic designer learning code and am not sure how to tackle this. This site is my senior project..Please help!!!

    remove the video code from that movieclip, assign that movieclip an instance name (eg, flv) and use:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <dren>
    <song>
    <title>Namasta</title>
    <artist>Dren A.D.</artist>
    <album>No Love Lost</album>
    <url>songs/namasta.mp3</url>
    <flv>whatever.f4v</flv>
    </song>
    <song>
    <title>Hoooorn</title>
    <artist>Dren A.D.</artist>
    <album>No Love Lost</album>
    <url>songs/hoooorn.mp3</url>
    <flv>whateverelse.f4v</flv>
    </song>
    </dren>
    /*-----------------Basic Variables-------------------*/
    /* Request a URL */
    /* lets you create a new Sound object, and load and play an external MP3 file into that object,  */
    /* The sound Channel controls the sound in the application  */
    /* This variable hold the  */
    /* used to calculate the current position of the song, for instance if you were to pause the song  */
    /* Used to Establish what song we are at, used for skipping songs  */
    /* When a song is playing its set to true when the song isnt playing its = false  */
    /* Creates Xml object so we can work with XML  */
    /* XML list that contains methods so we can work with one or more XML elements  */
    var getMusic:URLRequest;
    var music:Sound = new Sound();
    var soundChannel:SoundChannel;
    var currentSound:Sound = music;
    var pos:Number;
    var currentIndex:Number = 0;
    var songPlaying:Boolean = false;
    var xml:XML;
    var songlist:XMLList;
    /*--------Simple preloader----------------------------------------*/
    function loadProgress(event:ProgressEvent):void {
        var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
        percentLoaded = Math.round(percentLoaded * 100);
    if(percentLoaded > 20){
    trace("loading");
    } else{
    function completeHandler(event):void {
        trace("DONE");
    /*-------------------Load in Our XML ------------------------*/
    var loader:URLLoader = new URLLoader(); //create a new URLLoader Object
    loader.addEventListener(Event.COMPLETE, whenLoaded); //add an event listener to that object
    loader.load(new URLRequest("songs.xml")); //Requests our xml file that contains our song data
    function whenLoaded(e:Event):void //WhenLoaded function(see line 50) runs when line 50 is complete
    xml = new XML(e.target.data);
    songlist = xml.song; //accesses our song tag in our xml file
    getMusic = new URLRequest(songlist[0].url);//get music from songlist
    music.load(getMusic);//load music
    soundChannel = music.play();//plays the music
    songTXT.text = songlist[0].title; //gets song name from xml
    artistTXT.text = songlist[0].artist; //gets artist name
    albumTXT.text = songlist[0].album;  //gets album name
    flv.drenVid.source=songlist[0].flv
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);//runs the next song function when a song completes
    /*--------ads some mouse events to our buttons----------------------------------------*/
    next_btn.addEventListener(MouseEvent.CLICK, nextSong);
    prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
    pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
    /*--------Skips Songs----------------------------------------*/
    /*-most of below the vars is explained above---------*/
    function nextSong(e:Event):void
    if (currentIndex < (songlist.length() - 1))
    currentIndex++;
    else
    currentIndex = 0;
    var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
    var nextTitle:Sound = new Sound(nextReq);
    soundChannel.stop();
    songTXT.text = songlist[currentIndex].title;
    artistTXT.text = songlist[currentIndex].artist;
    albumTXT.text = songlist[currentIndex].album;
    soundChannel = nextTitle.play();
    flv.drenVid.source = songlist[currentIndex].flv
    songPlaying = true;
    currentSound = nextTitle;
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);
    /*--------Previous song and acceses the information in the xml File--------------------------*/
    /*--------most of below the vars is explained above-------------------------*/
    function prevSong(e:Event):void
    if (currentIndex > 0)
    currentIndex--;
    else
    currentIndex = songlist.length() - 1;
    var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
    var prevTitle:Sound = new Sound(nextReq);
    soundChannel.stop();
    songTXT.text = songlist[currentIndex].title;
    artistTXT.text = songlist[currentIndex].artist;
    albumTXT.text = songlist[currentIndex].album;
    soundChannel = prevTitle.play();
    flv.drenVid.source = songlist[currentIndex].flv
    songPlaying = true;
    currentSound = prevTitle;
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);
    function pauseSong(e:Event):void
    pos = soundChannel.position; //pause song at current position
    soundChannel.stop(); //stop sound
    songPlaying = false; // songPlaying is now equal to false
    play_btn.addEventListener(MouseEvent.CLICK,playSong);
    function playSong(e:Event):void
    if(songPlaying == false) //if songplaying is equal to false run function below
    soundChannel = currentSound.play(pos); //play from current position(used if it was paused)
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);//run nextSong function if current song is complete
    songPlaying = true; //songPlaying is now true
    play_btn.removeEventListener(MouseEvent.CLICK,playSong);

  • Seek bar for music

    Hi!
    I know flash has seek bar component for flv videos but I'm
    streaming music from net. I have a code for loading entire song but
    is it possible to add a seek bar to show what part of song is
    playing

    Yes, if you just want to track the progress of the sound
    file's playing, its pretty simple. You'll need a couple of
    variables, one to hold the value of the sound file's duration. And
    another to define the width of the seek bar object.
    In your download complete function give the duration variable
    the value of the sound's duration property. Then assign an
    enterframe function to update the seek bar. Just take the
    soundChannel.position property value and divide it by the sound
    file's duration property value. This will give you a ratio of the
    current position relative to the total time. Then multiply that
    value by the total width of the seek bar. Position the marker at
    that point on the seek bar.

  • Help needed to load different xml playlists by clicking button

    Hi there,
    I have a series of buttons, when i double click a button i want to load a new xml file
    I have some functioning code, but when i click on more than one button per run of the application, it will only use the first xml that was clicked / loaded.
    Does anyone have any suggestions I would be really grateful
    Thanks!
    // Music player populated via XML formatted data with associated .mp3 audio files
    // songs to play structured as an XMLList class
    // displays artist and song title in the interface
    cover.visible = false;
    cover2.visible = false;
    // song list base on an XMLList class
    var songList:XMLList;
    // total number of songs in list
    var songsTotal:Number;
    // sound class variable
    var sound:Sound;
    // sound channnel variable to play, pause and stop the sound
    var soundChannel:SoundChannel;
    // holds a reference to the current song playing
    var currentSong:Number = 0;
    // variable to store the song position when paused
    var songPosition:Number;
    // flag to check if current song is paused
    var songPaused:Boolean;
    //  loader for XML via a URL
    var XMLLoader:URLLoader = new URLLoader();
    // various buttons to control songs via the interface
    next_btn.addEventListener(MouseEvent.CLICK, onNext);
    prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
    pause_btn.addEventListener(MouseEvent.CLICK, onPause);
    play_btn.addEventListener(MouseEvent.CLICK, onPlay);
    album1.doubleClickEnabled=true;
    album2.doubleClickEnabled=true;
    album1.addEventListener(MouseEvent.DOUBLE_CLICK, loadalbum1);
    album2.addEventListener(MouseEvent.DOUBLE_CLICK, loadalbum2);
    // check the data has loaded correctly
    XMLLoader.addEventListener(Event.COMPLETE, processXML);
    // this function processes the XML data
    function processXML(e:Event):void {
    // create an XML playlist structure
    var anXMLplayList:XML = new XML(e.target.data);
    // associate the playlist songs with the internal song list
    songList = anXMLplayList.SONG;
    // set the total songs to those found in the XML data
    songsTotal = songList.length();
    // remove the eventlistener and restore variables
    XMLLoader.removeEventListener(Event.COMPLETE, processXML);
    XMLLoader = null;
    // this function starts the first song in the list
    // when the play_btn is pressed via the onPlay function
    function playSong(aSong:Number):void {
    // variables for the Title, Artist and associated song in the song list
    var aTitle = songList[aSong].@TITLE;
    var anArtist = songList[aSong].@ARTIST;
    var aURL = songList[aSong].@URL;
    // populate the interface with the current song data
    title_txt.text = aTitle;
    artist_txt.text = anArtist;
    // check to see if the sound channel is active
    if (soundChannel) {
      soundChannel.stop();
      soundChannel.removeEventListener(Event.SOUND_COMPLETE, onNext);
    // create a new sound object
    sound = new Sound();
    // load the sound from the URL song data
    sound.load(new URLRequest(aURL));
    // activate the sound channel via the play method
    soundChannel = sound.play();
    // when the current songh completes - play the next song via the onNext function
    soundChannel.addEventListener(Event.SOUND_COMPLETE, onNext);
    // this function plays the next song in the list
    function onNext(e:Event):void {
    // increment the current song
    currentSong++;
    // reset the current song if no more to play
    if (currentSong>=songsTotal) {
      currentSong=0;
    // else play the current song via the playSong method
    playSong(currentSong);
    // this function plays the previous song in the song list
    function onPrev(e:MouseEvent):void {
    currentSong--;
    if (currentSong<0) {
      currentSong = songsTotal-1;
    playSong(currentSong);
    // this function pauses the current song playing and sets the boolean flag
    // accordingly
    function onPause(e:MouseEvent):void {
    if (soundChannel) {
      songPosition = soundChannel.position;
      soundChannel.stop();
      songPaused=true;
    // this function plays the current song or restarts a paused song
    function onPlay(e:MouseEvent):void {
    if (songPaused) {
      soundChannel = sound.play(songPosition);
      songPaused=false;
    } else if (!soundChannel) {
      playSong(currentSong);
    function loadalbum1(e:Event):void {
    cover.visible = true;
    cover2.visible = false;
    // load the XML formated playlist
    XMLLoader.load(new URLRequest("playlist1.xml"));
    function loadalbum2(e:Event):void {
    cover2.visible = true;
    cover.visible = false;
    // load the XML formated playlist
    XMLLoader.load(new URLRequest("playlist2.xml"));

    You should try to limit the code you post to what is relevant to the problem... it is hard to track things down, especially when your code is not formatted properly with indentations.
    I didn't search farther than finding that you remove the event listener for the URLLoader...
    XMLLoader.removeEventListener(Event.COMPLETE, processXML);
    so if you remove it after you load the first file and do not restore one for it, then chances are you don't "processXML" any more than the first file you load

  • Will the FLVPlayback component play MP3's without FMS?

    Will the FLVPlayback Component (version 2.5.0.15) play an MP3 file without it having to be streamed through a Flash Media Server? All I'm looking for is to place a player into my Flash that plays an MP3 file that's in the same directory as the SWF.
    Here's my code... it's pretty simple:
    import fl.video.FLVPlayback;
    var myMusic:FLVPlayback = new FLVPlayback();
    myMusic.source = "mySong.mp3";
    myMusic.skin = "SkinOverPlayMute.swf";
    myMusic.skinBackgroundColor = 0xCCCCCC;
    addChild(myMusic);

    So the answer is no, correct?  FLVPlayback will not handle MP3 files?
    My new script, in case anyone is interested:
    import flash.media.Sound;
    import flash.net.URLRequest;
    var songTitle:String = "Shake Your Rump"
    var fileName:String = "shakeYourRump.mp3"
    var myMusic:Sound = new Sound(new URLRequest(fileName));
    var soundChannel:SoundChannel;
    var isPlaying:Boolean = false;
    var currentPosition:Number = 0;
    btn_Rewind.addEventListener(MouseEvent.CLICK,rewindMusic);
    btn_Play.addEventListener(MouseEvent.CLICK,playMusic);
    btn_Pause.addEventListener(MouseEvent.CLICK,pauseMusic);
    txt_Status.text = 'Click play to hear "' + songTitle + '"';
    function rewindMusic(myEvent:Event): void {
    currentPosition = 0;
    txt_Status.text = 'Rewinding "' + songTitle + '"  Click play to restart.';
    if (isPlaying) {
    soundChannel.stop();
    soundChannel = myMusic.play(currentPosition);
    txt_Status.text = 'Playing "' + songTitle + '"';
    function playMusic(myEvent:Event): void {
    if (!isPlaying) {
    soundChannel = myMusic.play(currentPosition);
    isPlaying = true;
    txt_Status.text = 'Playing "' + songTitle + '"';
    function pauseMusic(myEvent:Event):void {
    if (isPlaying) {
    currentPosition = soundChannel.position;
    soundChannel.stop();
    isPlaying = false;
    txt_Status.text = '"' + songTitle + '" is paused. Click play to resume.';
    stop();

  • Sound.Play() start time not consistent

    When I play an audio and give it a start time, eg sound.play(3366), it doesn't always play at that position.  I'm working on an application that is dependent on the soundChannel position, but after I start the sound, it sometimes doesn't start at the exact position I tell it too.  Sometimes the position starts at something like 3365.986394557823. I found a workaround of just using Math.ceil, but I still wonder why the position isn't true to the start parameter.  Anyone know why that is?

    yes?? The song is Paper Walls by Yellowcard. You can listen to it yourself, but to explain it they play this intro of the song (which I dislike) and then it pauses for a couple of seconds and then the actual song starts. listen to the song here: http://www.youtube.com/watch?v=GjENnmGf-Jc

  • Tracking sound progress

    Hello everyone. I've managed to build this mp3player but need to have the horontal component advance as the sound progreses. Any ideas?
    Thanks for any help!
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="appComplete()">
    <mx:Script>
            <![CDATA[
                import mx.controls.Alert;
                private static const MP3_URL:String = "sounds/sounda.mp3";
                private var sound:Sound = null;
                private var soundChannel:SoundChannel = null;
                private var playResumePosition:Number = 0;
                private var loaded:Boolean = false;
                private function appComplete():void
                    sound = new Sound();
                    sound.load(new URLRequest(MP3_URL));
                    sound.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOError):void
                            Alert.show("There was an error loading the MP3 file");   
                    sound.addEventListener(Event.COMPLETE, function(event:Event):void
                            loadingProgress.visible = false;
                            loaded = true;
                            soundChannel = sound.play();
                    sound.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void
                            loadingProgress.setProgress(event.bytesLoaded, event.bytesTotal);
                private function play():void
                    if (loaded)
                        soundChannel.stop();
                        soundChannel = sound.play(playResumePosition);
                private function stop():void
                    if (loaded)
                        playResumePosition = 0;
                        soundChannel.stop();                   
                private function pause():void
                    if (loaded)
                        playResumePosition = soundChannel.position;
                        soundChannel.stop();
                private function onChangeVolSlider(event:Event):void{
                 SoundMixer.soundTransform = new SoundTransform(event.currentTarget.value);
            ]]>
        </mx:Script>
        <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="MP3Player" showCloseButton="true" height="161" width="294" x="181" y="46">
        <mx:Button x="11" y="39" label="Play" click="play()" />
        <mx:Button x="70" y="39" label="Pause" click=" pause()" />
        <mx:Button x="137" y="40" label="Stop" click="stop()" />
        <mx:VSlider x="215" y="8" height="95" labels="[0,25,50,100]" change="onChangeVolSlider(event)" minimum="0" maximum="1" liveDragging="true" showDataTip="false" allowTrackClick="true" value="1"/>
        <mx:HSlider x="12" y="88" width="177"/>
        <mx:ProgressBar width="166" mode="manual" id="loadingProgress" x="15" y="6"/>
    </mx:TitleWindow>
    </mx:Application>

    The first step is to make sure that you are running the latest software.
    You should have version 1.2 for the iPod and 6.05 for iTunes.
    Do you have the correct software?
    "D"

  • To make a mp3 player stop

    hello to everyone.
    i have an mp3 player on my website that load a track list from a xml file.
    the problem is that the player start automatically when the website is loaded...and i want to make it stop since the beginning...so that if i want to here the music i have to push play

    var getMusic:URLRequest;
    var music:Sound = new Sound();
    var soundChannel:SoundChannel;
    var currentSound:Sound = music;
    var pos:Number;
    var currentIndex:Number = 0;
    var songPlaying:Boolean = false;
    var xml:XML;
    var songlist:XMLList;
    /*--------Simple preloader----------------------------------------*/
    function loadProgress(event:ProgressEvent):void {
    var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
    percentLoaded = Math.round(percentLoaded * 100);
    if(percentLoaded > 20){
    trace("loading");
    } else{
    function completeHandler(event):void {
    trace("DONE");
    /*-------------------Load in Our XML ------------------------*/
    var loader:URLLoader = new URLLoader(); //create a new URLLoader Object
    loader.addEventListener(Event.COMPLETE, whenLoaded); //add an event listener to that object
    loader.load(new URLRequest("songs.xml")); //Requests our xml file that contains our song data
    function whenLoaded(e:Event):void //WhenLoaded function(see line 50) runs when line 50 is complete
    xml = new XML(e.target.data);
    songlist = xml.song; //accesses our song tag in our xml file
    getMusic = new URLRequest(songlist[0].url);//get music from songlist
    music.load(getMusic);//load music
    soundChannel = music.play();//plays the music
    songTXT.text = songlist[0].title; //gets song name from xml
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);//runs the next song function when a song completes
    /*--------ads some mouse events to our buttons----------------------------------------*/
    next_btn.addEventListener(MouseEvent.CLICK, nextSong);
    prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
    pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
    /*--------Skips Songs----------------------------------------*/
    /*-most of below the vars is explained above---------*/
    function nextSong(e:Event):void
    if (currentIndex < (songlist.length() - 1))
    currentIndex++;
    else
    currentIndex = 0;
    var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
    var nextTitle:Sound = new Sound(nextReq);
    soundChannel.stop();
    songTXT.text = songlist[currentIndex].title;
    soundChannel = nextTitle.play();
    songPlaying = true;
    currentSound = nextTitle;
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);
    /*--------Previous song and acceses the information in the xml File--------------------------*/
    /*--------most of below the vars is explained above-------------------------*/
    function prevSong(e:Event):void
    if (currentIndex > 0)
    currentIndex--;
    else
    currentIndex = songlist.length() - 1;
    var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
    var prevTitle:Sound = new Sound(nextReq);
    soundChannel.stop();
    songTXT.text = songlist[currentIndex].title;
    soundChannel = prevTitle.play();
    songPlaying = true;
    currentSound = prevTitle;
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);
    function pauseSong(e:Event):void
    pos = soundChannel.position; //pause song at current position
    soundChannel.stop(); //stop sound
    songPlaying = false; // songPlaying is now equal to false
    play_btn.addEventListener(MouseEvent.CLICK,playSong);
    function playSong(e:Event):void
    if(songPlaying == false) //if songplaying is equal to false run function below
    soundChannel = currentSound.play(pos); //play from current position(used if it was paused)
    soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);//run nextSong function if current song is complete
    songPlaying = true; //songPlaying is now true
    play_btn.removeEventListener(MouseEvent.CLICK,playSong);

  • Sound position and length on Slider Component AS3

    Hello:
    I have the following working great:
    stop_btn.setStyle("icon", square_mc);
    player_btn.setStyle("icon", next_mc);
    import flash.events.Event
    import flash.events.MouseEvent;
    import flash.media.SoundTransform;
    var alreadyDefined:Boolean;
    volumen.value = 1;
    if(!alreadyDefined){
    alreadyDefined=true;
    var isPlaying:Boolean = new Boolean();
    var pausePosition:Number = new Number();
    var soundClip:Sound = new Sound();
    var sndChannel:SoundChannel;
    soundClip.load(new URLRequest("audio/music.mp3"));
    soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    player_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
    stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);
    function onComplete(evt:Event):void {
        sndChannel = soundClip.play();
        isPlaying = true;
    function btnPressController(evt:MouseEvent):void
        switch(isPlaying)
            case true:
                //controller.text ="Sound Paused";
                player_btn.setStyle("icon", pause_mc);
                pausePosition = sndChannel.position;
                sndChannel.stop();
                isPlaying = false;
            break;
            case false:
                //controller.text ="Sound Playing";
                player_btn.setStyle("icon", next_mc);
                sndChannel = soundClip.play(pausePosition);
                isPlaying = true;
            break;
    function btnPressStop(evt:MouseEvent):void
        pausePosition = 0;
        sndChannel.stop();
        //controller.text ="Play Sound";
        player_btn.setStyle("icon", next_mc);
        isPlaying = false;
    volumen.addEventListener(Event.CHANGE, sliderChanged);
    function sliderChanged(evt:Event):void {
    var vol:Number = volumen.value;
    volumen.liveDragging = true;
    var st:SoundTransform = new SoundTransform(vol);
    if(sndChannel != null){
        sndChannel.soundTransform = st;
    exit_btn.addEventListener(MouseEvent.CLICK, fexit);
    function fexit(event:MouseEvent):void{
        SoundMixer.stopAll(); 
        Loader(this.parent).unloadAndStop();
    I have another slider component on the movie with instance name PROGRESO
    I would like for PROGRESOnto indicate (update) the sounds progress as it plays and be able to scrub through the sound.
    Any idea how I can achieve this? Thanks for any help

    Thanks Andrei.
    But I really dont understand. You see, I am not too good (actually pretty bad) with Ationscript 3.
    Att.,
    Edwin
    I managed to get it to move each second though with this:
    var myTimer:Timer = new Timer(1000);
    myTimer.addEventListener(TimerEvent.TIMER, runTimer);
    myTimer.start();
    function runTimer(event:TimerEvent):void {
    trace("Hello");
    progreso.value = progreso.value+1;

  • Serious Help! Handling Sound Position And Speed!

    Take a look at this: https://sites.google.com/site/pardeepgames/Untitled-1.swf. It may take some time to load, sound is 42 seconds, see the second text field for time buffering.
    I recommend reading the Source Code below first.
    Now as you can see the pitch and speed functions are working perfectly, but the problem is that when you move the slider, the songTime text field dosen't work correctly. When you raise the pitch the songTime should just speed up the counting not change it's position, same when you lower the pitch, it should just slow down the counting not change it's position. Well that isn't working for me. The Source Code is there for you below and all the information you need is in the comments in the code. Please help me out. Oh and I recommend focusing on the songTime text field and then moving the slider.
    Source Code:
    Name of the slider: "slider".
    Name of the first text field: "songTime".
    Name of the second text field: "songTotalTime".
    import flash.events.Event;
    import flash.events.SampleDataEvent;
    import flash.media.Sound;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import fl.events.SliderEvent;
    import flash.media.SoundChannel;
    var _playbackSpeed:Number = 2;
    var sound:Sound;
    var sound2:Sound; // Copy of the original sound, to get the right information about the sound because the pitch shifting for the original sound variable ruins it up.
    var myChannel:SoundChannel = new SoundChannel();
    var _loadedMP3Samples:ByteArray;
    var _phase:Number;
    var _numSamples:int;
    var request:URLRequest = new URLRequest("https://sites.google.com/site/pardeepgames/Not%20Afraid%20Instrumental.mp3");
    var songTimeTime:Number = 1000; // The variable that allows the songTime's speed to change accoriding to the value of the slider. See in line 32.
    loadAndplay10(request);
    addEventListener(Event.ENTER_FRAME, enterFrame);
    function enterFrame(event:Event):void
      progressBar.scaleX = myChannel.position / sound2.length;
      _playbackSpeed = slider.value;
      songTimeTime = 1000 / slider.value;
      songTime.text = convertTime(myChannel.position);
      songTotalTime.text = convertTimeLength(sound2.length);
    function loadAndplay10(request:URLRequest):void
      sound = new Sound();
      sound2 = new Sound();
      sound.addEventListener(Event.COMPLETE, mp3Complete);
      sound.load(request);
      sound2.load(request);
    function playLoadedSound(s:Sound):void
      var bytes:ByteArray = new ByteArray();
      s.extract(bytes, int(s.length * 44.1));
      play10(bytes);
    function mp3Complete(event:Event):void
      playLoadedSound(sound);
    function play10(bytes:ByteArray):void
      stop10();
      sound = new Sound();
      sound.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
      _loadedMP3Samples = bytes;
      _numSamples = bytes.length / 8;
      _phase = 0;
      myChannel = sound.play();
    function stop10():void
      if (sound)
      sound.removeEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData);
      myChannel.stop();
    function onSampleData( event:SampleDataEvent ):void
      var l:Number;
      var r:Number;
      var outputLength:int = 0;
      while (outputLength < 2048)
      // until we have filled up enough output buffer
      // move to the correct location in our loaded samples ByteArray
      _loadedMP3Samples.position = int(_phase) * 8;// 4 bytes per float and two channels so the actual position in the ByteArray is a factor of 8 bigger than the phase
      // read out the left and right channels at this position
      l = _loadedMP3Samples.readFloat();
      r = _loadedMP3Samples.readFloat();
      // write the samples to our output buffer
      event.data.writeFloat(l);
      event.data.writeFloat(r);
      outputLength++;
      // advance the phase by the speed...
      _phase +=  _playbackSpeed;
      // and deal with looping (including looping back past the beginning when playing in reverse)
      if (_phase < 0)
      _phase +=  _numSamples;
      else if (_phase >= _numSamples)
      _phase -=  _numSamples;
    function convertTime(milliSeconds:Number):String
      var Minutes:Number = (milliSeconds % (songTimeTime * 60 * 60)) / (songTimeTime * 60);
      var Seconds:Number = (milliSeconds % (songTimeTime * 60 * 60)) % (songTimeTime * 60) / songTimeTime;
      if (Minutes < 10)
      var displayMinutes:String = "0" + Math.floor(Minutes);
      else
      displayMinutes = Math.floor(Minutes).toString();
      if (Seconds < 10)
      var displaySeconds:String = "0" + Math.floor(Seconds);
      else
      displaySeconds = Math.floor(Seconds).toString();
      return displayMinutes + ":" + displaySeconds;
    function convertTimeLength(milliSeconds:Number):String
      var Minutes2:Number = (milliSeconds % (1000 * 60 * 60)) / (1000 * 60);
      var Seconds2:Number = (milliSeconds % (1000 * 60 * 60)) % (1000 * 60) / 1000;
      if (Minutes2 < 10)
      var displayMinutes2:String = "0" + Math.floor(Minutes2);
      else
      displayMinutes2 = Math.floor(Minutes2).toString();
      if (Seconds2 < 10)
      var displaySeconds2:String = "0" + Math.floor(Seconds2);
      else
      displaySeconds2 = Math.floor(Seconds2).toString();
      return displayMinutes2 + ":" + displaySeconds2;

    this is a public forum.  no one here (or anywhere else that i know of) is obligated to work for you for free.
    your options are to keep working on this yourself or hire someone to help you.  if you can narrow down the problem's location and post the problematic code you could still get free help.
    or just wait.  given enough time maybe someone willing to donate their time to help you will read your post.

  • AS3 play and pause timeline as well as soundchannels

    I am trying to make global playback control buttons to play & pause the timeline as well as the sound channels. I have managed to get the buttons to function correctly with  controlling the timeline but I need them to also work with the  soundchannels too.
    Here is the code I created for the buttons:
    btnStop.visible = true;
    btnPlay.visible = false;
    var movieclip:MovieClip;
    function stopMovieClip(mc:MovieClip):void{
    mc.stop();
    for (var i:int = 0; i < mc.numChildren; i++)
    var mcChild = mc.getChildAt(i);
    if (mcChild is MovieClip) stopMovieClip(mcChild);
    btnPlay.visible = true;
    btnStop.visible = false;
    function playMovieClip(mcPlaying:MovieClip):void{
    mcPlaying.play();
    for (var j:int = 0; j < mcPlaying.numChildren; j++)
    var mcPlay = mcPlaying.getChildAt(j);
    if (mcPlay is MovieClip) playMovieClip(mcPlay);
    btnStop.visible = true;
    btnPlay.visible = false;
    btnStop.addEventListener(MouseEvent.CLICK, stopAll);
    function stopAll(event:MouseEvent):void
    stopMovieClip(con);
    btnPlay.addEventListener(MouseEvent.CLICK, PlayMC);
    function PlayMC(event:MouseEvent):void
    playMovieClip(con);
    And the code for the soundchannels:
    import flash.media.SoundChannel;
    var strokeVOSound:strokeVO = new strokeVO();
    var strokeVOChannel:SoundChannel = new SoundChannel();
    var bleedVOSound:bleedVO = new bleedVO();
    var bleedVOChannel:SoundChannel = new SoundChannel();
    yellow_mc.visible=false;
    blue_mc.visible=false;
    strokebtn_mc.addEventListener(MouseEvent.CLICK, displayStroke);
    strokebtn_mc.buttonMode = true;
    function displayStroke(e:MouseEvent):void {
    trace ('Clicked')
    yellow_mc.visible=true;
    blue_mc.visible=false;
    bleedVOChannel.stop();
    strokeVOChannel = strokeVOSound.play();
    bleedbtn_mc.addEventListener(MouseEvent.CLICK, displaybleed);
    bleedbtn_mc.buttonMode = true;
    function displaybleed(e:MouseEvent):void {
    yellow_mc.visible=false;
    blue_mc.visible=true;
    trace ('Clicked')
    strokeVOChannel.stop();
    bleedVOChannel = bleedVOSound.play();
    The soundchannels are triggered by a movieclip which acts as a button.
    Any help would be much appreciated.
    Thanks

    For the two soundchannel sounds you have, you will need to keep track if and which one is playing so that you can use some logic to stop the sound right after you mark where the sound was (position)  so that you can resume playing it again when the play button is selected.
    So if the stroke sound is started, you could assign a boolean variable named something like 'strokeplaying' to be true (setting the other sounds similar boolean false).  Then, in your pause function you would test to see if strokeplaying is true and if it is, store the position property and stop the channel playing. 
    When play is selected, similarly, you test if that sound is true and if so you restart it using the position value you stored as the starting point.  You do the same for the other sound... remembering that it is possible neither is playing when pause it clicked.

Maybe you are looking for

  • How to call web service using J2SE 1.3?

    Dear All, i have developed a web service by jdev 10.1.3 (JAX-RPC with web service security enabled). i generate the ws proxy (jdev 10.1.3) and run it with wsclient_extended.jar (required JDK 1.4.1 or above??). but one of my client say he has to use J

  • Problem running reports to network printer

    Application Server Enterprise Edition 10g (9.0.4.1) Customer is having some difficulty printing reports to printers attached to client PCs and shared on the network. Occasionally, when a report is requested by the application with DESTYPE=PRINTER, DE

  • Remove Software component

    Hi, Could you please let me know how to delete a software component in XI. Regards, Chandra

  • How iphoto files are saved

    When I got my mac I transferred all my photos over and saved them in Pictures and then imported them into iPhoto - now im wondering does this mean I know have two copies of my photos, can I delete the original files and theyll still be in my iphoto l

  • Last software update SLOWWWWWED down my G4

    Just seeing if anyone had any problems after the last software update for OS 10.4.6? After I installed the latest update, my system was so slow it sometimes took up to 10 minutes to open an application. Mail would take about 1/2 hour- lots of spinnin