Ignore:
Timestamp:
Oct 4, 2011, 1:52:48 PM (13 years ago)
Author:
george
Message:
  • Fixed: Start/stop playback control.
  • Added: Track position and Length handling.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolAudio/Systems/UAudioSystemMPlayer.pas

    r276 r277  
     1// MPlayer slave command list: http://www.mplayerhq.hu/DOCS/tech/slave.txt
     2
    13unit UAudioSystemMPlayer;
    24
     
    68
    79uses
    8   Classes, SysUtils, UAudioSystem, Process, Math, Dialogs;
     10  Classes, SysUtils, UAudioSystem, Process, Math, Dialogs, DateUtils;
    911
    1012const
     
    3537  private
    3638    FProcess: TProcess;
    37     FProcessActive: Boolean;
    38     FPlaying: Boolean;
    3939    FVolume: Real;
    4040    function GetProcessOutput: string;
     
    108108procedure TPlayerMPlayer.SendCommand(Command: string);
    109109begin
    110   Command := Command + LineEnding;// #10; // MPLayer always needs #10 as Lineending, no matter if win32 or linux
     110  Command := Command + #10; // MPLayer always needs #10 as Lineending, no matter if win32 or linux
    111111  try
    112     if FProcessActive then FProcess.Input.Write(Command[1], System.Length(Command));
     112    if FProcess.Running then FProcess.Input.Write(Command[1], System.Length(Command));
    113113  except
    114114    raise Exception.Create(SSendCommandException);
     
    117117
    118118function TPlayerMPlayer.GetLength: TDateTime;
    119 begin
     119var
     120  tmps: string;
     121  I: Integer;
     122  Time: Real;
     123begin
     124  if FPlaying and fProcess.Running then begin
     125    repeat
     126      SendCommand('get_time_length');
     127      Sleep(5);
     128      tmps := GetProcessOutput;
     129    until Pos('LENGTH', tmps) > 0;
     130    I := LastDelimiter('=', tmps);
     131    if I > 0 then begin
     132      Tmps := StringReplace(Tmps, '.', ',', [rfReplaceAll]);
     133      Time := StrToFloat(Copy(tmps, I + 1, System.Length(tmps)));
     134      Result := Time * OneSecond;
     135    end;
     136  end;
    120137end;
    121138
     
    136153    I := LastDelimiter('=', tmps);
    137154    if I > 0 then begin
     155      Tmps := StringReplace(Tmps, '.', ',', [rfReplaceAll]);
    138156      Time := StrToFloat(Copy(tmps, I + 1, System.Length(tmps)));
    139       Time := Time * 1000;
    140       Result := Round(Time);
     157      Result := Time * OneSecond;
    141158    end else Result := -1;
    142159  end else Result := -1;
     
    168185procedure TPlayerMPlayer.SetPosition(AValue: TDateTime);
    169186begin
     187  if FPlaying and FProcess.Running then begin
     188    SendCommand('set_property time_pos ' + StringReplace(FloatToStr(AValue / OneSecond), ',', '.', [rfReplaceAll]));
     189  end;
    170190end;
    171191
Note: See TracChangeset for help on using the changeset viewer.