Changeset 665 for trunk/Music.pas


Ignore:
Timestamp:
Jul 9, 2025, 4:45:12 PM (12 hours ago)
Author:
chronos
Message:
  • Fixed: Playing music on Windows.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Music.pas

    r664 r665  
    44
    55uses
    6   Classes, SysUtils, Dialogs, uos_flat;
     6  Classes, SysUtils, Dialogs, uos_flat, ctypes;
    77
    88type
     
    1919    AutoPlayNext: Boolean;
    2020    procedure Initialize;
    21     procedure EndPlay;
    22     procedure LoopEndProc;
     21    procedure EndPlay(PlayerIndex: cint32);
    2322    function GetNextPlaylistItem: string;
    2423    procedure PlayNext(Data: PtrInt);
     
    4645procedure TMusicPlayer.Initialize;
    4746var
    48   res: Integer;
    4947  SndFileFileName: string;
    5048  PortAudioFileName: string;
     
    5351  if Initialized then Exit;
    5452
     53  {$IFDEF UNIX}
    5554  SndFileFileName := 'libsndfile.so.1';
    5655  PortAudioFileName := 'libportaudio.so';
    5756  XmpFileName := 'libxmp.so.4';
     57  {$ELSE}
     58    {$if defined(cpu64)}
     59    SndFileFileName := 'LibSndFile-64.dll';
     60    PortAudioFileName := 'LibPortaudio-64.dll';
     61    XmpFileName := 'libxmp-64.dll';
     62    {$ELSE}
     63    SndFileFileName := 'LibSndFile-32.dll';
     64    PortAudioFileName := 'LibPortaudio-32.dll';
     65    XmpFileName := 'libxmp-32.dll';
     66    {$ENDIF}
     67  {$ENDIF}
    5868
    5969  if (SndFileFileName <> 'system') and  (SndFileFileName <> '') then
     
    6171   SndFileFileName := SndFileFileName + '.2';
    6272
    63   res := uos_LoadLib(PChar(PortAudioFileName), PChar(SndFileFileName), Nil, Nil,
    64     Nil, Nil, PChar(XmpFileName));
     73  if uos_LoadLib(PChar(PortAudioFileName), PChar(SndFileFileName), Nil, Nil,
     74    Nil, Nil, PChar(XmpFileName)) <> 0 then
     75    raise Exception.Create('Error while loading audio libraries.');
    6576
    6677  Initialized := True;
    6778end;
    6879
    69 procedure TMusicPlayer.EndPlay;
    70 begin
    71   if AutoPlayNext then Application.QueueAsyncCall(PlayNext, 0);
    72 end;
    73 
    74 procedure TMusicPlayer.LoopEndProc;
    75 var
    76   Position: Integer;
    77 begin
    78   Position := uos_InputPosition(PlayerIndex1, InputIndex1);
    79   if Position >= InputLength then
    80     Play;
     80procedure TMusicPlayer.EndPlay(PlayerIndex: cint32);
     81begin
     82  if AutoPlayNext and (PlayerIndex = PlayerIndex1) then Application.QueueAsyncCall(PlayNext, 0);
    8183end;
    8284
     
    152154
    153155  AutoPlayNext := False;
    154   //uos_Stop(PlayerIndex1);
    155   uos_StopAndWait(PlayerIndex1);
    156 
    157   //Inc(PlayerIndex1);
     156  uos_Stop(PlayerIndex1);
     157
     158  Inc(PlayerIndex1);
    158159
    159160  uos_CreatePlayer(PlayerIndex1);
Note: See TracChangeset for help on using the changeset viewer.