Am Ende gibt es eine Fehlermeldung:
DirectShow_MP3.exe funktioniert nicht mehr.
Wer findet den Fehler oder eine Lösung?
Im Anhang ist die EXE und das MP3-File.
Delphi-Quellcode:
program DirectShow_MP3;
{$APPTYPE CONSOLE}
uses
DirectShow9,
Windows,
ActiveX;
var
pGraph : IGraphBuilder;
pControl : IMediaControl;
pEvent : IMediaEvent;
hr : HRESULT;
evCode : integer = 0;
begin
hr := CoInitialize(
nil);
if FAILED(hr)
then
begin
Writeln('
ERROR - Could not initialize COM library');
Halt(0);
end;
// Create the filter graph manager and query for interfaces.
hr := CoCreateInstance(CLSID_FilterGraph,
nil, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, pGraph);
if FAILED(hr)
then
begin
Writeln('
ERROR - Could not create the Filter Graph Manager.');
Halt(0);
end;
pGraph.QueryInterface(IID_IMediaControl, pControl);
pGraph.QueryInterface(IID_IMediaEvent, pEvent);
// IMPORTANT: Change this string to a file on your system.
hr := pGraph.RenderFile('
Alarm01.mp3',
nil);
// Build the graph
if SUCCEEDED(hr)
then
begin
hr := pControl.Run();
// Run the graph
if SUCCEEDED(hr)
then
begin
pEvent.WaitForCompletion(300000, evCode);
// 5 Min wait for completion
//pEvent.WaitForCompletion(INFINITE, evCode);
// Note: Do not use INFINITE in a real application, because it
// can block indefinitely.
end;
end;
(* WRONG CODE
pControl._Release();
pEvent._Release();
pGraph._Release();
CoUninitialize();
//WriteLn('Press Return');
//ReadLn;
Halt(0);
end. *)
//CORRECTION
pControl:=nil;
pEvent:=nil;
pGraph:=nil;
CoUninitialize;
end.