Mysql->php->mp3->loadSound glitches

I have some problems with an mp3-player I’ve built. It’s too much code to post here so I’ll give you a clear (hopefully) description of my player and my problems…with some snippets of code perhaps.

The player’s functionality:

  1. The player gets the file URLs from a mySQL database via php in XML form. (Works fine)
  2. The player has play,stop,next and previous buttons. (Works fine, almost)
  3. You can also seek to different positions with a seek-bar. (Works fine)
  4. You can change volume with another bar.
  5. The current trackname (also from XML) and the next trackname is shown.

That’s the player and it’s interface functions.

So what’s my problem?

Well, I never notice it - since I’m sitting on a test server and everything is loaded directly from my HD - but my friend (who I’m building the site for) gets some very strange effects when using the player:

When skipping to a new track, or when pressing “next” a few times in a row, the player starts to studder/glitch and it becomes impossible to stop the sound. It keeps glitching until you reload the page. By glitching I mean: The sound stops, then suddenly you can hear a short burst of sound, a pause, a few short bursts, a pause…and so on.

I’ve tried to replicate the problem without any luck (I’ve now tried at work, connecting to my home computer, and I’ve gotten the same error). I got another friend to try and he only managed to break it after pressing “next” about ten times as rapid as he could…but it broke none the less, and that’s unacceptable for me.

Here’s a quick run-through of the code:

Clicking “next” runs a playListSkip(“next”) - function:

function playListSkip(where:String){
    endGuiUpdate();
    if ( where == "next" ){
        currTrack++;
        currTrack %= nodeMp3.length;
        
    } else if ( where == "prev" ) {
        currTrack--;
        if(currTrack < 0){
            currTrack = nodeMp3.length - 1;
        }
    }
    scrollingTxt = returnTrackName(currTrack) + " ";
    playListPlay(currTrack);
    beginGuiUpdate();
}

Here, as you see, I stop a setInterval with the function “endGuiUpdate” which stops redrawing the players visual stuff. Then it simply checks if I want to skip forward or backward in the XML-array I have. When it knows which, it runs the function playListPlay():

function playListPlay(trackNr){
    checkLoadInt = setInterval(checkIfLoaded, 50);
    sound.stop();
    sound.loadSound(nodeMp3[trackNr], true);
}

This function streams the mp3-URL stored in the nodeMp3-array, and I think this is where the problem lies.
First, an interval starts to check if the sound being loaded has reached a certain amount of bytes. Then I stops the sound (I just noticed that the interval lies first, which it shouldn’t, but that part seems to work anyway when I trace). Lastly, it loads the new mp3.

When the checkIfLoaded function runs each 50 ms, it checks if sound.bytesLoaded >= 10000. If it is, the track starts to play:

function checkIfLoaded(){
    endGuiUpdate();
    endTextUpdate();
    endSeekUpdate();
    tr("checkIfLoaded ran");
    if(sound.getBytesLoaded() >= 10000){
        sound.stop();
        setVol(currVol);
        sound.start();
        clearInterval(checkLoadInt);
        beginScrollTextUpdate();
        beginGuiUpdate();
        beginTextUpdate();
    }
}

As you can see, I have sound.stop() at several locations. This is because my friend(s) reports that when they skip to the next track, they sometimes get a short “pop” from the next track, then silence while it “buffers”…and then it begins to play correctly. So I’ve tried to eliminate any “pops” by stopping the sound, several times, to make sure that nothing is there.
I have also removed the sound.onLoad function, since it replays the file when the whole file is downloaded - even if you’ve told loadSound to stream.

I hope someone has the energy to read all this, and know what I’m doing wrong because I can’t figure out what the problem could possibly be.

Should I perhaps delete the sound object and create a new one for each track? How would that be possible?

** Thanks in advance!
:hr:
**