Changeset 280 for CoolAudio/Systems
- Timestamp:
- Oct 5, 2011, 12:40:56 PM (13 years ago)
- Location:
- CoolAudio/Systems
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolAudio/Systems/UAudioSystem.pas
r278 r280 31 31 TPlayer = class(TComponent) 32 32 private 33 procedure SetPlaying(AValue: Boolean);34 33 protected 34 FActive: Boolean; 35 35 FFileName: string; 36 36 FAudioSystem: TAudioSystem; 37 37 FPlaying: Boolean; 38 function GetMuted: Boolean; virtual; abstract; 39 procedure SetMuted(AValue: Boolean); virtual; abstract; 40 function GetLength: TDateTime; virtual; abstract; 41 function GetPosition: TDateTime; virtual; abstract; 42 function GetVolume: Real; virtual; abstract; 43 procedure SetPosition(AValue: TDateTime); virtual; abstract; 44 procedure SetVolume(AValue: Real); virtual; abstract; 38 procedure SetActive(AValue: Boolean); virtual; 39 procedure SetPlaying(AValue: Boolean); virtual; 40 function GetMuted: Boolean; virtual; 41 procedure SetMuted(AValue: Boolean); virtual; 42 function GetLength: TDateTime; virtual; 43 function GetPosition: TDateTime; virtual; 44 function GetVolume: Real; virtual; 45 procedure SetPosition(AValue: TDateTime); virtual; 46 procedure SetVolume(AValue: Real); virtual; 45 47 procedure SetFileName(AValue: string); virtual; 46 48 public 47 procedure Play; virtual; abstract; 48 procedure Pause; virtual; abstract; 49 procedure Stop; virtual; abstract; 49 procedure Play; virtual; 50 procedure Pause; virtual; 51 procedure Stop; virtual; 52 procedure Open; virtual; 53 procedure Close; virtual; 50 54 property Position: TDateTime read GetPosition write SetPosition; 51 55 property Length: TDateTime read GetLength; … … 55 59 property FileName: string read FFileName write SetFileName; 56 60 property Playing: Boolean read FPlaying write SetPlaying; 61 property Active: Boolean read FActive write SetActive; 57 62 constructor Create; virtual; 63 destructor Destroy; override; 58 64 end; 59 65 … … 125 131 { TPlayer } 126 132 133 procedure TPlayer.SetActive(AValue: Boolean); 134 begin 135 if FActive = AValue then Exit; 136 FActive := AValue; 137 end; 138 127 139 procedure TPlayer.SetPlaying(AValue: Boolean); 128 140 begin … … 131 143 end; 132 144 145 function TPlayer.GetMuted: Boolean; 146 begin 147 Result := False; 148 end; 149 150 procedure TPlayer.SetMuted(AValue: Boolean); 151 begin 152 end; 153 154 function TPlayer.GetLength: TDateTime; 155 begin 156 Result := 0; 157 end; 158 159 function TPlayer.GetPosition: TDateTime; 160 begin 161 Result := 0; 162 end; 163 164 function TPlayer.GetVolume: Real; 165 begin 166 Result := 0; 167 end; 168 169 procedure TPlayer.SetPosition(AValue: TDateTime); 170 begin 171 end; 172 173 procedure TPlayer.SetVolume(AValue: Real); 174 begin 175 end; 176 133 177 procedure TPlayer.SetFileName(AValue: string); 134 178 begin … … 137 181 end; 138 182 183 procedure TPlayer.Play; 184 begin 185 end; 186 187 procedure TPlayer.Pause; 188 begin 189 end; 190 191 procedure TPlayer.Stop; 192 begin 193 end; 194 195 procedure TPlayer.Open; 196 begin 197 Active := True; 198 end; 199 200 procedure TPlayer.Close; 201 begin 202 Active := False; 203 end; 204 139 205 constructor TPlayer.Create; 140 206 begin 141 207 end; 208 209 destructor TPlayer.Destroy; 210 begin 211 Active := False; 212 inherited Destroy; 142 213 end; 143 214 -
CoolAudio/Systems/UAudioSystemMPlayer.pas
r279 r280 105 105 tmps := GetEnvironmentVariable('PATH'); 106 106 repeat 107 I := pos(':', tmps);107 I := Pos(PathSeparator, tmps); 108 108 if I = 0 then I := Length(tmps); 109 109 tmppath := IncludeTrailingPathDelimiter(Copy(tmps, 0, I - 1)) + MPlayerExecutableName; … … 118 118 begin 119 119 inherited Create; 120 FPath := '';120 FPath := FindPath; 121 121 end; 122 122 -
CoolAudio/Systems/UAudioSystemWindows.pas
r279 r280 7 7 {$IFDEF Windows} 8 8 uses 9 Classes, SysUtils, UAudioSystem, MMSystem;9 Windows, Classes, SysUtils, UAudioSystem, MMSystem, DateUtils; 10 10 11 11 type 12 TAudioSystemWindows = class(TAudioSystem) 13 public 14 PlayerIndex: Integer; 15 end; 16 17 TMPDeviceTypes = (dtAutoSelect, dtAVIVideo, dtCDAudio, dtDAT, dtDigitalVideo, dtMMMovie, 18 dtOther, dtOverlay, dtScanner, dtSequencer, dtVCR, dtVideodisc, dtWaveAudio); 12 19 13 20 { TPlayerWindows } … … 15 22 TPlayerWindows = class(TPlayer) 16 23 private 24 FHandle: HWND; 25 FDeviceId: MCIDEVICEID; 26 FDeviceType: TMPDeviceTypes; 27 FFlags: Longint; 28 FUseNotify: Boolean; 29 FNotify: Boolean; 30 FUseWait: Boolean; 31 FWait: Boolean; 32 FAliasName: string; 33 procedure DoClose; 34 procedure DoOpen; 35 procedure SetDeviceType(AValue: TMPDeviceTypes); 36 procedure CheckError(AValue: Integer); 37 function GetErrorMessage(Code: Integer): string; 38 procedure SetActive(AValue: Boolean); override; 39 procedure SetNotify(AValue: Boolean); 40 procedure SetWait(AValue: Boolean); 41 function GetPosition: TDateTime; override; 42 procedure SetPosition(AValue: TDateTime); override; 43 function GetLength: TDateTime; override; 44 public 17 45 procedure Play; override; 18 46 procedure Pause; override; 19 47 procedure Stop; override; 48 constructor Create; override; 49 destructor Destroy; override; 50 property DeviceType: TMPDeviceTypes read FDeviceType write SetDeviceType; 51 property Handle: HWND read FHandle; 52 property Wait: Boolean read FWait write SetWait; 53 property Notify: Boolean read FNotify write SetNotify; 20 54 end; 21 55 {$ENDIF} 22 56 57 resourcestring 58 SMCIUnknownError = 'Unknown error code'; 59 23 60 implementation 24 61 … … 27 64 { TPlayerWindows } 28 65 66 procedure TPlayerWindows.SetDeviceType(AValue: TMPDeviceTypes); 67 begin 68 if FDeviceType = AValue then Exit; 69 FDeviceType := AValue; 70 end; 71 72 procedure TPlayerWindows.CheckError(AValue: Integer); 73 begin 74 if AValue <> 0 then raise Exception.Create('Error ' + IntToStr(AValue) + ': ' + GetErrorMessage(AValue)); 75 end; 76 77 function TPlayerWindows.GetErrorMessage(Code: Integer): string; 78 var 79 ErrMsg: array[0..4095] of Char; 80 begin 81 if not mciGetErrorString(Code, ErrMsg, SizeOf(ErrMsg)) then 82 Result := SMCIUnknownError 83 else SetString(Result, ErrMsg, StrLen(ErrMsg)); 84 end; 85 86 procedure TPlayerWindows.SetActive(AValue: Boolean); 87 begin 88 if FActive = AValue then Exit; 89 inherited SetActive(AValue); 90 if AValue then DoOpen else DoClose; 91 end; 92 93 procedure TPlayerWindows.SetNotify(AValue: Boolean); 94 begin 95 if FNotify = AValue then Exit; 96 FNotify := AValue; 97 FUseNotify := True; 98 end; 99 100 procedure TPlayerWindows.SetWait(AValue: Boolean); 101 begin 102 if FWait = AValue then Exit; 103 FWait := AValue; 104 FUseWait := True; 105 end; 106 107 function TPlayerWindows.GetPosition: TDateTime; 108 var 109 Parm: TMCI_Status_Parms; 110 begin 111 FFlags := mci_Wait or mci_Status_Item; 112 Parm.dwItem := mci_Status_Position; 113 CheckError(mciSendCommand(FDeviceID, mci_Status, FFlags, Longint(@Parm))); 114 Result := Parm.dwReturn * OneMillisecond; 115 end; 116 117 procedure TPlayerWindows.SetPosition(AValue: TDateTime); 118 var 119 Parm: TMCI_Seek_Parms; 120 begin 121 if FDeviceID <> 0 then begin 122 FFlags := 0; 123 if FUseWait then 124 begin 125 if FWait then FFlags := mci_Wait; 126 FUseWait := False; 127 end 128 else FFlags := mci_Wait; 129 if FUseNotify then 130 begin 131 if FNotify then FFlags := FFlags or mci_Notify; 132 FUseNotify := False; 133 end; 134 FFlags := FFlags or mci_To; 135 Parm.dwTo := Round(AValue / OneMillisecond); 136 CheckError(mciSendCommand(FDeviceID, mci_Seek, FFlags, Longint(@Parm))); 137 if FPlaying then Play; 138 end; 139 end; 140 141 function TPlayerWindows.GetLength: TDateTime; 142 var 143 Parm: TMCI_Status_Parms; 144 begin 145 FFlags := mci_Wait or mci_Status_Item; 146 Parm.dwItem := mci_Status_Length; 147 mciSendCommand(FDeviceID, mci_Status, FFlags, Longint(@Parm)); 148 Result := Parm.dwReturn * OneMillisecond; 149 end; 150 29 151 procedure TPlayerWindows.Play; 30 begin 31 PlaySound(); 32 sndPlaySound(FFileName, SND_ASYNC); 152 var 153 Parm: TMCI_Play_Parms; 154 begin 155 if FDeviceID = 0 then DoOpen; 156 157 FFlags := 0; 158 if FUseNotify then 159 begin 160 if FNotify then FFlags := mci_Notify; 161 FUseNotify := False; 162 end else FFlags := mci_Notify; 163 if FUseWait then 164 begin 165 if FWait then FFlags := FFlags or mci_Wait; 166 FUseWait := False; 167 end; 168 CheckError(mciSendCommand(FDeviceID, mci_Play, FFlags, Longint(@Parm))); 169 FPlaying := True; 33 170 end; 34 171 35 172 procedure TPlayerWindows.Pause; 36 begin 37 inherited Pause; 173 var 174 Parm: TMCI_Generic_Parms; 175 begin 176 if FPlaying then begin 177 CheckError(mciSendCommand(FDeviceID, mci_Pause, FFlags, Longint(@Parm))); 178 FPlaying := False; 179 end else begin 180 CheckError(mciSendCommand(FDeviceID, mci_Resume, FFlags, Longint(@Parm))); 181 FPlaying := True; 182 end; 38 183 end; 39 184 40 185 procedure TPlayerWindows.Stop; 41 begin 42 sndPlaySound(nil, 0); 186 var 187 Parm: TMCI_Generic_Parms; 188 begin 189 FFlags := 0; 190 if FUseNotify then 191 begin 192 if FNotify then FFlags := mci_Notify; 193 FUseNotify := False; 194 end else FFlags := mci_Notify; 195 if FUseWait then 196 begin 197 if FWait then FFlags := FFlags or mci_Wait; 198 FUseWait := False; 199 end; 200 CheckError(mciSendCommand(FDeviceID, mci_Stop, FFlags, Longint(@Parm))); 201 FPlaying := False; 202 end; 203 204 constructor TPlayerWindows.Create; 205 begin 206 inherited Create; 207 end; 208 209 destructor TPlayerWindows.Destroy; 210 begin 211 Active := False; 212 inherited Destroy; 213 end; 214 215 procedure TPlayerWindows.DoOpen; 216 const 217 DeviceName: array[TMPDeviceTypes] of PChar = ('', 'AVIVideo', 'CDAudio', 'DAT', 218 'DigitalVideo', 'MMMovie', 'Other', 'Overlay', 'Scanner', 'Sequencer', 219 'VCR', 'Videodisc', 'WaveAudio'); 220 var 221 Parm: TMCI_Open_Parms; 222 begin 223 if FDeviceId <> 0 then DoClose; 224 225 FillChar(Parm, SizeOf(TMCI_Open_Parms), 0); 226 Parm.dwCallback := 0; 227 Parm.lpstrDeviceType := DeviceName[FDeviceType]; 228 Parm.lpstrElementName := PChar(FFileName); 229 230 FFlags := 0; 231 232 if FUseWait then 233 begin 234 if FWait then FFlags := mci_Wait; 235 FUseWait := False; 236 end 237 else 238 FFlags := mci_Wait; 239 240 if FUseNotify then 241 begin 242 if FNotify then FFlags := FFlags or mci_Notify; 243 FUseNotify := False; 244 end; 245 246 if FDeviceType <> dtAutoSelect then 247 FFlags := FFlags or mci_Open_Type; 248 249 if FDeviceType <> dtAutoSelect then 250 FFlags := FFlags or mci_Open_Type 251 else 252 FFlags := FFlags or MCI_OPEN_ELEMENT; 253 254 //Parm.dwCallback := Handle; 255 CheckError(mciSendCommand(0, mci_Open, FFlags, Longint(@Parm))); 256 FDeviceID := Parm.wDeviceID; 257 FActive := True; 258 end; 259 260 procedure TPlayerWindows.DoClose; 261 var 262 Parm: TMCI_Generic_Parms; 263 begin 264 if FDeviceId <> 0 then begin 265 FFlags := 0; 266 if FUseWait then 267 begin 268 if FWait then FFlags := mci_Wait; 269 FUseWait := False; 270 end 271 else FFlags := mci_Wait; 272 if FUseNotify then 273 begin 274 if FNotify then FFlags := FFlags or mci_Notify; 275 FUseNotify := False; 276 end; 277 CheckError(mciSendCommand(FDeviceId, mci_Close, FFlags, Longint(@Parm))); 278 FDeviceId := 0; 279 FActive := False; 280 end; 43 281 end; 44 282
Note:
See TracChangeset
for help on using the changeset viewer.