![]() |
AW: Syntax SendMCICommand
Delphi-Quellcode:
destructor Destroy(alias: string); reintroduce;
Delphi-Quellcode:
fehlt noch das alias hinter play ;)
if autoplay then
play; und alias mciplayer bei duration wurde noch nicht ersetzt.
Delphi-Quellcode:
gruss
// Calculate duration
command := ('set mciplayer time format milliseconds wait'); mciSendString(command, return, resultSize, 0); command := ('status mciplayer length wait'); mciSendString(command, return, resultSize, 0); if (StrLen(return) > 0) then duration := StrToInt(return) else duration := 0; |
AW: Syntax SendMCICommand
Okay.
Jetzt hat er nur noch ein Problem damit, dass das command ein PWideChar ist, aber alias ein string... also zum Beispiel
Delphi-Quellcode:
wirft einen Fehler auf (Inkompatible Typen: 'PWideChar und 'String').
command := ('set '+ alias +' time format milliseconds wait');
Hingegen
Delphi-Quellcode:
erkennt er nicht als Fehler...
command := PWideChar('open "' + fileName + '" type ' + dtype + ' alias ' + alias + ' wait');
|
AW: Syntax SendMCICommand
Wäre es nicht geschickter den Alias beim Create in einer private Variable zu merken, dann muss der nicht bei jedem Aufruf wieder mitgegeben werden, sondern die Instanz verwaltet den selber?
Und der direkte Aufruf von Destroy ist ja auch nicht StateOfTheArt :) besser wäre Free Evtl. könnte man im Create auch einen eindeutigen Namen erzeugen lassen, dann verwaltet die Klasse das komplett selber |
AW: Syntax SendMCICommand
Zitat:
Wenn zwei Instanzen Arbeiten benötigst du auch 2 Unterschiedliche alias was man machen könnte wäre ein FAlias: array of string. Zitat:
Ist mir bei den ganzen hin und her nicht aufgefallen ;) Das problem aber in Destroy steht das Alias welches behandelt werden muss. Nur mit Free geht es so im moment nicht. Müßte man dann erst noch mit einer variablen ändern. Im moment geht es erstmal so. Im Anhang die korrigierte mit PWideChar.. Zitat:
Lust das zu ändern ? gruss |
AW: Syntax SendMCICommand
Super, so zusammengeschustert klappt alles :)
Top :thumb: Zitat:
Vielen Dank an alle Beteiligten von meiner Seite nochmal :dp: EDIT: Eine Frage noch: Was mache ich jetzt, Free oder Destroy? Zitat:
|
AW: Syntax SendMCICommand
Zitat:
Im moment Destroy da unser alias noch nicht von der Classe selbst verwaltet wird. gruss |
AW: Syntax SendMCICommand
Zitat:
|
AW: Syntax SendMCICommand
Zitat:
Delphi-Quellcode:
Aufruf mit:
unit uMciPlayer;
interface uses Classes; type TMciPlayerState = ( mpsWait, mpsPlay, mpsPause ); TMciPlayer = class private FAlias : string; FState : TMciPlayerState; FDuration : Integer; FLastResult : Cardinal; FLastResultStr : string; function GetPosition : Integer; protected procedure DoCallCommand( const CmdStr : string ); public constructor Create( const aAlias, aFileName : string; AutoPlay : Boolean = False ); destructor Destroy; override; procedure Play; procedure Stop; procedure Pause; procedure Resume; property Alias : string read FAlias; property State : TMciPlayerState read FState; property Duration : Integer read FDuration; property Position : Integer read GetPosition; property LastResult : Cardinal read FLastResult; property LastResultStr : string read FLastResultStr; end; implementation uses Winapi.MMSystem, System.SysUtils; { TMciPlayer } constructor TMciPlayer.Create( const aAlias, aFileName : string; AutoPlay : Boolean ); begin inherited Create; FState := mpsWait; FAlias := aAlias; FDuration := 0; DoCallCommand( 'open "' + aFileName + '" alias ' + aAlias ); if LastResult = 0 then begin DoCallCommand( 'set ' + FAlias + ' time format milliseconds wait' ); DoCallCommand( 'status ' + FAlias + ' length wait' ); FDuration := StrToIntDef( LastResultStr, 0 ); end; if AutoPlay then Play; end; destructor TMciPlayer.Destroy; begin DoCallCommand( 'close ' + FAlias + ' wait' ); inherited; end; procedure TMciPlayer.DoCallCommand( const CmdStr : string ); var lResultSize : Cardinal; lReturn : array [0 .. 255] of WideChar; begin lResultSize := 255; FLastResult := mciSendString( PWideChar( CmdStr ), lReturn, lResultSize, 0 ); if FLastResult <> 0 then begin mciGetErrorString( FLastResult, lReturn, 255 ); FLastResultStr := lReturn; end else FLastResultStr := lReturn; end; function TMciPlayer.GetPosition : Integer; begin DoCallCommand( 'status ' + FAlias + ' position wait' ); Result := StrToIntDef( FLastResultStr, 0 ); end; procedure TMciPlayer.Pause; begin if FState = mpsPlay then begin DoCallCommand( 'pause ' + FAlias + ' notify' ); FState := mpsPause; end; end; procedure TMciPlayer.Play; begin if FState = mpsWait then begin DoCallCommand( 'play ' + FAlias + ' notify' ); FState := mpsPlay; end else Resume; end; procedure TMciPlayer.Resume; begin if FState = mpsPause then begin DoCallCommand( 'resume ' + FAlias + ' notify' ); FState := mpsPlay; end; end; procedure TMciPlayer.Stop; begin if FState <> mpsWait then begin DoCallCommand( 'stop ' + FAlias + ' notify' ); FState := mpsWait; end; end; end.
Delphi-Quellcode:
Könnte man auch noch schön erweitern, so dass man auch das Soundfile der Instanz ändern kann.
var
Player1, Player2 : TMciPlayer; begin Player1 := TMciPlayer.Create( 'Player1', 'Sample1.wav' ); Player2 := TMciPlayer.Create( 'Irgendwas2', 'Sample2.mp3' ); Player1.Play; Player2.Play; // irgendwann dann auch mal Player1.Free; Player2.Free; end; |
AW: Syntax SendMCICommand
@Sir Rufo
Feine sache.. Gut gelößt mit dem DoCallCommand ;) gruss |
AW: Syntax SendMCICommand
Zitat:
Delphi-Quellcode:
geht, dann geht garantiert auch
if assigned(myMCIPlayer) then myMCIPlayer.Destroy;
Delphi-Quellcode:
, denn rate mal was Free macht.
myMCIPlayer.Free;
Wenn aber myMCIPlayer weiterhin verwendet wird, dann sollte man
Delphi-Quellcode:
verwenden.
FreeAndNil(myMCIPlayer);
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz