![]() |
AW: Syntax SendMCICommand
Zitat:
Es beendet nicht die richitge Instanze über myMCIPlayer.Destroy('Player1'); Ich habe/hatte kein myMCIPlayer.Destroy; Hättest du aber gesehen wenn du den älteren Quelltext angeschaut hättest..
Delphi-Quellcode:
destructor Destroy(alias: string); reintroduce;
Wenn zwei Intanzen des Player spielen würden wie willst du dann !NUR! mit Free die richtige Instanz abhängig vom Alias beenden? Zeig mir das mal ohne den alten Code zu ändern. Mit dem neuen geänderten Code von Sir Rufo ist das jetzt kein problem mehr.. Zitat:
Vielleicht doch besser Raten? :mrgreen: gruss |
AW: Syntax SendMCICommand
Nur mal so für Spaß eine Version, die sich den Alias selber erzeugt und somit wesentlich einfacher im Handling ist, da jede Instanz per Design einen eindeutigen Alias (GUID) bekommt.
Delphi-Quellcode:
unit uMciPlayer;
interface uses Classes; type TMciPlayerState = ( mpsClosed, mpsStopped, mpsPlaying, mpsPaused ); TMciPlayer = class private FAlias : string; FState : TMciPlayerState; FDuration : Integer; FFileName : string; function GetPosition : Integer; procedure SetFileName( const Value : string ); function GetState : TMciPlayerState; procedure SetState( const Value : TMciPlayerState ); protected procedure DoCallCommand( const CmdStr : string ); overload; procedure DoCallCommand( const CmdStr : string; out ResultStr : string ); overload; procedure DoOpen; procedure DoClose; public constructor Create; destructor Destroy; override; procedure Open( const aFileName : string; aAutoPlay : Boolean = False ); procedure Play; procedure Stop; procedure Pause; procedure Resume; property State : TMciPlayerState read GetState; property Duration : Integer read FDuration; property Position : Integer read GetPosition; property Alias : string read FAlias; property FileName : string read FFileName write SetFileName; end; implementation uses Winapi.MMSystem, System.SysUtils; { TMciPlayer } constructor TMciPlayer.Create; begin inherited Create; FState := mpsClosed; FAlias := GUIDToString( TGUID.NewGuid ); FFileName := ''; FDuration := 0; end; destructor TMciPlayer.Destroy; begin DoClose; inherited; end; procedure TMciPlayer.DoCallCommand( const CmdStr : string ); var ResultStr : string; begin DoCallCommand( CmdStr, ResultStr ); end; procedure TMciPlayer.DoCallCommand( const CmdStr : string; out ResultStr : string ); var lResultCode : Cardinal; lResultSize : Cardinal; lReturn : array [0 .. 255] of WideChar; begin lResultSize := 255; lResultCode := mciSendString( PWideChar( CmdStr ), lReturn, lResultSize, 0 ); if lResultCode <> 0 then begin mciGetErrorString( lResultCode, lReturn, 255 ); raise Exception.CreateFmt( 'MCI-Fehler [%d] %s' + sLineBreak + '%s', [lResultCode, lReturn, CmdStr] ); end; ResultStr := lReturn; end; procedure TMciPlayer.DoClose; begin if State <> mpsClosed then begin DoCallCommand( 'close ' + FAlias + ' wait' ); SetState( mpsClosed ); end; end; procedure TMciPlayer.DoOpen; var ResultStr : string; begin if ( State = mpsClosed ) and ( FileName <> '' ) and ( Alias <> '' ) then begin FDuration := 0; DoCallCommand( 'open "' + FFileName + '" alias ' + FAlias ); DoCallCommand( 'set ' + FAlias + ' time format milliseconds wait' ); DoCallCommand( 'status ' + FAlias + ' length wait', ResultStr ); FDuration := StrToIntDef( ResultStr, 0 ); SetState( mpsStopped ); end; end; function TMciPlayer.GetPosition : Integer; var ResultStr : string; begin if State <> mpsClosed then begin DoCallCommand( 'status ' + FAlias + ' position wait', ResultStr ); Result := StrToIntDef( ResultStr, 0 ); end else Result := -1; end; function TMciPlayer.GetState : TMciPlayerState; begin Result := FState; end; procedure TMciPlayer.Open( const aFileName : string; aAutoPlay : Boolean ); begin FileName := aFileName; if aAutoPlay then Play; end; procedure TMciPlayer.Pause; begin if State = mpsPlaying then begin DoCallCommand( 'pause ' + FAlias + ' notify' ); SetState( mpsPaused ); end; end; procedure TMciPlayer.Play; begin DoOpen; case State of mpsStopped : begin DoCallCommand( 'play ' + FAlias + ' notify' ); SetState( mpsPlaying ); end; mpsPaused : Resume; end; end; procedure TMciPlayer.Resume; begin if State = mpsPaused then begin DoCallCommand( 'resume ' + FAlias + ' notify' ); SetState( mpsPlaying ); end; end; procedure TMciPlayer.SetFileName( const Value : string ); begin if Value <> FFileName then begin DoClose; FFileName := Value; end; end; procedure TMciPlayer.SetState( const Value : TMciPlayerState ); begin if Value <> FState then begin FState := Value; end; end; procedure TMciPlayer.Stop; begin if State > mpsStopped then begin DoCallCommand( 'stop ' + FAlias + ' notify' ); SetState( mpsStopped ); DoCallCommand( 'seek ' + FAlias + ' to start notify' ); end; end; end. |
AW: Syntax SendMCICommand
Zitat:
Die Frage .. Wie wirkt sich dieser lange string auf die Performance/Geschwindigkeit aus. Bin immer noch mein Rad am drehen um zu erfahren was Free denn nun ist. :lol: gruss |
AW: Syntax SendMCICommand
Zitat:
|
AW: Syntax SendMCICommand
Zitat:
Ruf die Guid mal jede Millisekunde in realzeit FDuration auf ;) Wie schnell zeichnet dann der String im Format 00:00:00 Denke das geht schon auf die Performance.. Frame Rate wäre hier interessant. Deine Lösung finde ich gut! Ist nur mal so Interesse halber. EDIT: Hab mich nochmal informiert! Sollte kein problem sein das Alias als Guid zu übergeben. gruss |
AW: Syntax SendMCICommand
Hey Leute,
ich grabe den Thread eben nochmal aus :) Wenn ich meine Sounds nicht alle von der Festplatte sondern aus einer Ressourcendatei sound.res laden möchte, funktioniert das auch mit der MCIPlayer-Unit und wie? :stupid: So nach dem Motto:
Delphi-Quellcode:
nur eben mit Sir Rufo's Unit...
{$R sound.res}
[...] PlaySound(PChar(1), HInstance, snd_ASync or snd_Memory or snd_Resource); |
AW: Syntax SendMCICommand
Geht aber nicht mit der von (mir erstellten) und von Sir Rufo geänderten Unit.
Diese müßte dann erst noch angepasst werden. Stichwort! mmioInstallIOProc.. TMemoryStream.. Vielleicht hilft dir Sir Rufo falls du nicht weiter kommst bzw. weist wie du das umsetzen könntest. EDIT: Davon abgesehen gibt es doch probleme unter verwendung von Guid als Alias.. Spätestens dann wenn der Pfad Inklusive der Guid länger als 79 Zeichen ist. Zitat:
|
AW: Syntax SendMCICommand
Okay, danke, sagt mir nichts, ich versuch mich mal schlau zu machen...
|
AW: Syntax SendMCICommand
Zitat:
gruss Edit: Zitat:
|
AW: Syntax SendMCICommand
Zitat:
- ich schreibe ein Programm in dem ich sequentielle und parallele Audio-Ausgaben machen möchte - der Kauf der BASS.DLL finanziell nicht in Frage kommt und auch dem Rahmen des Programms nicht entspricht. die Variante, die Sir Rufo da gecoded hat finde ich sehr hilfreich, aber ich habe dazu noch Fragen: Wie richte ich darin das "notify-event" ein, um über das vollständige Abspielen einer wav-Datei unterrichtet zu werden? Geht das überhaupt? Oder muß ich über die duration einen Timer einrichten der mich informiert? Der Ablauf mit Create, Open, Free muß nach meiner Beobachtung auch genau eingehalten werden, sonst gibt's Fehler. Ich kann zwar auf mehreren "Kanälen" ausgeben, aber nicht mehrere auf einem einer ID nacheinander. Oder ganz andere Frage: Wie würdet ihr das Problem lösen? (ohne Bass.dll!) Danke! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:45 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