unit u_music;

interface

uses SysUtils, zglHeader, Dialogs;

procedure MusicInit;
procedure PlayMusic;
procedure StopMusic;


var Msc:array of zglPSound;
    PlayId:Integer=-1;

implementation

procedure StopMusic;
begin
  if PlayId>=0 then begin
    snd_Stop(Msc[PlayId], 0);
  end;
  PlayId:=-1;
end;

procedure PlayMusic;
begin
  StopMusic;
  PlayId:=Random(Length(Msc));
  snd_Play(Msc[PlayId], true);
  snd_SetVolume(Msc[PlayId], 0, 0.5);
end;

procedure MusicInit;
var sr:TSearchRec;
begin
  if FindFirst('Data/Music/*.ogg', faAnyFile, sr) = 0 then begin
    repeat
      SetLength(Msc, Length(Msc)+1);
      Msc[Length(Msc)-1] := snd_LoadFromFile('Data/Music/'+sr.Name, 1);
    until FindNext(sr)<>0;
  end;
end;

end.
