Changeset 277 for CoolAudio


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.
Location:
CoolAudio
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • CoolAudio/Demo/Demo.lpi

    r276 r277  
    4343        <IsPartOfProject Value="True"/>
    4444        <UnitName Value="Demo"/>
    45         <UsageCount Value="28"/>
     45        <UsageCount Value="29"/>
    4646      </Unit0>
    4747      <Unit1>
     
    5151        <ResourceBaseClass Value="Form"/>
    5252        <UnitName Value="UMainForm"/>
     53        <IsVisibleTab Value="True"/>
    5354        <EditorIndex Value="0"/>
    5455        <WindowIndex Value="0"/>
    55         <TopLine Value="58"/>
    56         <CursorPos X="66" Y="65"/>
    57         <UsageCount Value="28"/>
     56        <TopLine Value="1"/>
     57        <CursorPos X="14" Y="3"/>
     58        <UsageCount Value="29"/>
    5859        <Loaded Value="True"/>
    5960        <LoadedDesigner Value="True"/>
     
    7475        <TopLine Value="1"/>
    7576        <CursorPos X="20" Y="111"/>
    76         <UsageCount Value="13"/>
     77        <UsageCount Value="14"/>
    7778        <Loaded Value="True"/>
    7879      </Unit3>
     
    104105        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    105106        <UnitName Value="UAudioSystemMPlayer"/>
    106         <IsVisibleTab Value="True"/>
    107107        <EditorIndex Value="3"/>
    108108        <WindowIndex Value="0"/>
    109         <TopLine Value="258"/>
    110         <CursorPos X="8" Y="260"/>
    111         <UsageCount Value="13"/>
     109        <TopLine Value="231"/>
     110        <CursorPos X="1" Y="243"/>
     111        <UsageCount Value="14"/>
    112112        <Loaded Value="True"/>
    113113      </Unit7>
     
    125125        <EditorIndex Value="2"/>
    126126        <WindowIndex Value="0"/>
    127         <TopLine Value="70"/>
    128         <CursorPos X="32" Y="82"/>
    129         <UsageCount Value="23"/>
     127        <TopLine Value="17"/>
     128        <CursorPos X="56" Y="29"/>
     129        <UsageCount Value="24"/>
    130130        <Loaded Value="True"/>
    131131      </Unit9>
     
    145145        <TopLine Value="2427"/>
    146146        <CursorPos X="24" Y="2429"/>
    147         <UsageCount Value="10"/>
     147        <UsageCount Value="11"/>
    148148        <Loaded Value="True"/>
    149149      </Unit11>
     
    199199        <TopLine Value="13"/>
    200200        <CursorPos X="21" Y="26"/>
    201         <UsageCount Value="10"/>
     201        <UsageCount Value="11"/>
    202202        <Loaded Value="True"/>
    203203      </Unit18>
     
    209209        <TopLine Value="1"/>
    210210        <CursorPos X="1" Y="1"/>
    211         <UsageCount Value="10"/>
     211        <UsageCount Value="11"/>
    212212        <Loaded Value="True"/>
    213213      </Unit19>
     
    216216      <Position1>
    217217        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    218         <Caret Line="232" Column="1" TopLine="212"/>
     218        <Caret Line="129" Column="1" TopLine="113"/>
    219219      </Position1>
    220220      <Position2>
    221221        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    222         <Caret Line="244" Column="42" TopLine="228"/>
     222        <Caret Line="130" Column="1" TopLine="113"/>
    223223      </Position2>
    224224      <Position3>
    225225        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    226         <Caret Line="239" Column="1" TopLine="228"/>
     226        <Caret Line="131" Column="1" TopLine="113"/>
    227227      </Position3>
    228228      <Position4>
    229229        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    230         <Caret Line="240" Column="1" TopLine="228"/>
     230        <Caret Line="128" Column="1" TopLine="113"/>
    231231      </Position4>
    232232      <Position5>
    233233        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    234         <Caret Line="241" Column="1" TopLine="228"/>
     234        <Caret Line="129" Column="1" TopLine="113"/>
    235235      </Position5>
    236236      <Position6>
    237237        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    238         <Caret Line="242" Column="1" TopLine="228"/>
     238        <Caret Line="130" Column="1" TopLine="113"/>
    239239      </Position6>
    240240      <Position7>
    241241        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    242         <Caret Line="243" Column="1" TopLine="228"/>
     242        <Caret Line="131" Column="1" TopLine="113"/>
    243243      </Position7>
    244244      <Position8>
    245245        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    246         <Caret Line="240" Column="12" TopLine="228"/>
     246        <Caret Line="132" Column="1" TopLine="113"/>
    247247      </Position8>
    248248      <Position9>
    249249        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    250         <Caret Line="219" Column="53" TopLine="203"/>
     250        <Caret Line="133" Column="1" TopLine="113"/>
    251251      </Position9>
    252252      <Position10>
    253253        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    254         <Caret Line="240" Column="1" TopLine="227"/>
     254        <Caret Line="134" Column="1" TopLine="114"/>
    255255      </Position10>
    256256      <Position11>
    257257        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    258         <Caret Line="241" Column="1" TopLine="227"/>
     258        <Caret Line="135" Column="1" TopLine="115"/>
    259259      </Position11>
    260260      <Position12>
    261261        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    262         <Caret Line="242" Column="1" TopLine="227"/>
     262        <Caret Line="136" Column="1" TopLine="116"/>
    263263      </Position12>
    264264      <Position13>
    265265        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    266         <Caret Line="243" Column="1" TopLine="227"/>
     266        <Caret Line="139" Column="1" TopLine="119"/>
    267267      </Position13>
    268268      <Position14>
    269         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    270         <Caret Line="240" Column="12" TopLine="227"/>
     269        <Filename Value="UMainForm.pas"/>
     270        <Caret Line="63" Column="1" TopLine="59"/>
    271271      </Position14>
    272272      <Position15>
    273         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    274         <Caret Line="110" Column="37" TopLine="108"/>
     273        <Filename Value="UMainForm.pas"/>
     274        <Caret Line="70" Column="1" TopLine="61"/>
    275275      </Position15>
    276276      <Position16>
    277         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    278         <Caret Line="239" Column="1" TopLine="227"/>
     277        <Filename Value="UMainForm.pas"/>
     278        <Caret Line="64" Column="10" TopLine="62"/>
    279279      </Position16>
    280280      <Position17>
    281         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    282         <Caret Line="240" Column="1" TopLine="227"/>
     281        <Filename Value="UMainForm.pas"/>
     282        <Caret Line="35" Column="19" TopLine="23"/>
    283283      </Position17>
    284284      <Position18>
    285         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    286         <Caret Line="241" Column="1" TopLine="227"/>
     285        <Filename Value="../Systems/UAudioSystem.pas"/>
     286        <Caret Line="54" Column="62" TopLine="33"/>
    287287      </Position18>
    288288      <Position19>
    289         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    290         <Caret Line="240" Column="10" TopLine="227"/>
     289        <Filename Value="UMainForm.pas"/>
     290        <Caret Line="35" Column="19" TopLine="23"/>
    291291      </Position19>
    292292      <Position20>
    293         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    294         <Caret Line="126" Column="50" TopLine="108"/>
     293        <Filename Value="UMainForm.pas"/>
     294        <Caret Line="64" Column="20" TopLine="52"/>
    295295      </Position20>
    296296      <Position21>
    297297        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    298         <Caret Line="230" Column="1" TopLine="218"/>
     298        <Caret Line="246" Column="16" TopLine="225"/>
    299299      </Position21>
    300300      <Position22>
    301301        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    302         <Caret Line="231" Column="1" TopLine="218"/>
     302        <Caret Line="245" Column="1" TopLine="225"/>
    303303      </Position22>
    304304      <Position23>
    305305        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    306         <Caret Line="109" Column="1" TopLine="97"/>
     306        <Caret Line="246" Column="1" TopLine="226"/>
    307307      </Position23>
    308308      <Position24>
    309309        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    310         <Caret Line="110" Column="1" TopLine="97"/>
     310        <Caret Line="248" Column="1" TopLine="228"/>
    311311      </Position24>
    312312      <Position25>
    313         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    314         <Caret Line="111" Column="1" TopLine="97"/>
     313        <Filename Value="UMainForm.pas"/>
     314        <Caret Line="64" Column="19" TopLine="50"/>
    315315      </Position25>
    316316      <Position26>
    317         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    318         <Caret Line="112" Column="1" TopLine="97"/>
     317        <Filename Value="../Systems/UAudioSystem.pas"/>
     318        <Caret Line="54" Column="41" TopLine="42"/>
    319319      </Position26>
    320320      <Position27>
    321321        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    322         <Caret Line="116" Column="1" TopLine="97"/>
     322        <Caret Line="36" Column="26" TopLine="29"/>
    323323      </Position27>
    324324      <Position28>
    325         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    326         <Caret Line="233" Column="45" TopLine="218"/>
     325        <Filename Value="../Systems/UAudioSystem.pas"/>
     326        <Caret Line="29" Column="56" TopLine="17"/>
    327327      </Position28>
    328328      <Position29>
    329329        <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    330         <Caret Line="112" Column="45" TopLine="97"/>
     330        <Caret Line="243" Column="1" TopLine="231"/>
    331331      </Position29>
    332332      <Position30>
    333         <Filename Value="../Systems/UAudioSystemMPlayer.pas"/>
    334         <Caret Line="230" Column="1" TopLine="218"/>
     333        <Filename Value="UMainForm.pas"/>
     334        <Caret Line="67" Column="35" TopLine="55"/>
    335335      </Position30>
    336336    </JumpHistory>
  • CoolAudio/Demo/UMainForm.lfm

    r276 r277  
    6161    Top = 90
    6262    Width = 417
     63    Max = 100
     64    OnChange = TrackBar1Change
    6365    Position = 0
    6466    Anchors = [akTop, akLeft, akRight]
     
    7072    top = 48
    7173  end
     74  object TimerPlayback: TTimer
     75    OnTimer = TimerPlaybackTimer
     76    left = 112
     77    top = 144
     78  end
    7279end
  • CoolAudio/Demo/UMainForm.pas

    r276 r277  
    11unit UMainForm;
    22
    3 {$mode objfpc}{$H+}
     3{$mode Delphi}{$H+}
    44
    55interface
     
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, UAudioSystem, UAudioSystemFMOD, UAudioSystemMPlayer;
     9  ComCtrls, ExtCtrls, UAudioSystem, UAudioSystemFMOD, UAudioSystemMPlayer;
    1010
    1111type
     
    2020    Edit1: TEdit;
    2121    OpenDialog1: TOpenDialog;
     22    TimerPlayback: TTimer;
    2223    TrackBar1: TTrackBar;
    2324    procedure Button1Click(Sender: TObject);
     
    2728    procedure FormCreate(Sender: TObject);
    2829    procedure FormDestroy(Sender: TObject);
     30    procedure TimerPlaybackTimer(Sender: TObject);
     31    procedure TrackBar1Change(Sender: TObject);
    2932  private
    3033    { private declarations }
     
    5760end;
    5861
     62procedure TMainForm.TimerPlaybackTimer(Sender: TObject);
     63begin
     64  if Player.Playing then begin
     65    TrackBar1.OnChange := nil;
     66    TrackBar1.Position := Trunc(Player.Position / Player.Length * TrackBar1.Max);
     67    TrackBar1.OnChange := TrackBar1Change;
     68  end;
     69end;
     70
     71procedure TMainForm.TrackBar1Change(Sender: TObject);
     72begin
     73  Player.Position := TrackBar1.Position / TrackBar1.Max * Player.Length;
     74end;
     75
    5976procedure TMainForm.ButtonPlayClick(Sender: TObject);
    6077begin
  • CoolAudio/Systems/UAudioSystem.pas

    r276 r277  
    2929  TPlayer = class(TComponent)
    3030  private
     31    procedure SetPlaying(AValue: Boolean);
    3132  protected
    3233    FFileName: string;
     
    5152    property AudioSystem: TAudioSystem read FAudioSystem write FAudioSystem;
    5253    property FileName: string read FFileName write SetFileName;
     54    property Playing: Boolean read FPlaying write SetPlaying;
    5355    constructor Create; virtual;
    5456  end;
     
    6163
    6264{ TPlayer }
     65
     66procedure TPlayer.SetPlaying(AValue: Boolean);
     67begin
     68  if FPlaying = AValue then Exit;
     69  if AValue then Play else Stop;
     70end;
    6371
    6472procedure TPlayer.SetFileName(AValue: string);
  • 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.