Problem making music play in my game. Plays ok but when the song needs to change the game crashes:

Code:
procedure setupmusic(thefile:string;looping:boolean);
var
  WaveFormat: TwaveFormatEx;
begin
    if (MainFm.Music1.enabled=true)then
  begin
     mainFm.Audio.AutoUpdate := True;
    mainfm.Audio.BufferLength := 1000;
    mainfm.Audio.FileName :=TheFile;
    mainfm.Audio.Looped := looping;


    MakePCMWaveFormatEx(WaveFormat, 22050,        mainfm.Audio.Format.wBitsPerSample, 2);
    mainfm.DXSound1.Primary.SetFormat(waveFormat);

    end;
end;
I pass the file to be played in then say audio.play; It is some problem caused by not freeing the music? or not clearing the buffer?

Anyone know what I am doing wrong here, driving me nuts.