R
rainM
Unregistered / Unconfirmed
GUEST, unregistred user!
我搞了一个播放器用于同时播放两路视频文件,程序能够编译,但是在运行的时候却出现"interface not supported",不知道是何原因,还请各位帮忙看一下.我的程序代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DSPack, DSUtil, ExtCtrls, DirectShow9, ActiveX;
type
TForm1 = class(TForm)
fg1: TFilterGraph;
fg2: TFilterGraph;
Button1: TButton;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
SG1, VideoRender1, AudioRender1,FSour1:IBaseFilter;
SG2, VideoRender2, AudioRender2,FSour2:IBaseFilter;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var MediaType : TMediaType;
begin
fg1.Active:=true;
CoCreateInstance(CLSID_VideoMixingRenderer,nil,CLSCTX_InPROC,IID_IBASEFilter,VideoRender1);
COCreateInstance(CLSID_AsyncReader,nil,CLSCTX_INPROC,IID_IBASEFilter,fsour1);
CoCreateInstance(CLSID_SampleGrabber,nil,CLSCTX_INPROC,IID_IBASEFilter,SG1);
CoCreateInstance(CLSID_DSoundRender,nil,CLSCTX_INPROC,IID_IBASEFilter,AudioRender1);
with fg1 as IFilterGraphdo
begin
addfilter(FSour1 as IBaseFilter,StringToOLEStr('dpfs1'));
addfilter(VideoRender1 as IBaseFilter,StringToOLEStr('dpvr1'));
addfilter(SG1 as IBaseFilter,StringToOLEStr('dpsg1'));
addfilter(AudioRender1 as IBaseFilter,StringToOLEStr('dpar1'));
end;
with FSour1 as IFileSourceFilterdo
Load(StringToOLEStr('f:/Hands_L.mpg'),nil);
MediaType:=TMediaType.Create(MEDIATYPE_Video);
MediaType.ResetFormatBuffer;
ZeroMemory(MediaType.AMMediaType,sizeof(TAMMediaType));
MediaType.MajorType:=MEDIATYPE_Video;
MediaType.SubType:=MEDIASUBTYPE_RGB32;
with SG1 as ISampleGrabberdo
SetMediaType(MediaType.AMMediaType^);
with fg1 as ICaptureGraphBuilder2do
begin
RenderStream(nil,nil,FSour1,SG1,VideoRender1);
RenderStream(nil,nil,FSour1,nil,AudioRender1);
end;
with SG1 as ISampleGrabberdo
SetBufferSamples(true);
MediaType.Free;
with fg1 as IMediaPositiondo
put_CurrentPosition(0);
fg2.Active:=False;
fg2.Active:=True;
Cocreateinstance(CLSID_VideoMixingRenderer,nil,CLSCTX_INPROC,IID_IBASEFilter,VideoRender2);
Cocreateinstance(CLSID_AsyncReader,nil,CLSCTX_INPROC,IID_IBASEFilter,fsour2);
Cocreateinstance(CLSID_SampleGrabber,nil,CLSCTX_INPROC,IID_IBASEFilter,SG2);
Cocreateinstance(CLSID_DSoundRender,nil,CLSCTX_INPROC,IID_IBASEFilter,AudioRender2);
with fg2 as IFilterGraphdo
begin
addfilter(FSour2 as IBaseFilter,StringToOLEStr('dpfs2'));
addfilter(VideoRender2 as IBaseFilter,StringToOLEStr('dpvr2'));
addfilter(SG2 as IBaseFilter,StringToOLEStr('dpsg2'));
addfilter(AudioRender2 as IBaseFilter,StringToOLEStr('dpar2'));
end;
with FSour2 as IFileSourceFilterdo
Load(StringToOLEStr('f:/Hands_R.mpg'),nil);
MediaType:=TmediaType.Create(MEDIATYPE_Video);
MediaType.ResetFormatBuffer;
ZeroMemory(MediaType.AMMediaType,sizeof(TAMMediaType));
MediaType.MajorType:=MEDIATYPE_Video;
MediaType.FormatType:=FORMAT_VideoInfo;
MediaType.SubType:=MEDIASUBTYPE_RGB32;
with SG2 as ISampleGrabberdo
SetMediaType(MediaType.AMMediaType^);
with fg2 as ICaptureGraphBuilder2do
begin
RenderStream(nil,nil,FSour2,SG2,VideoRender2);
RenderStream(nil,nil,FSour2,nil,AudioRender2);
end;
with fg2 as IMediaPositiondo
put_CurrentPosition(0);
if fg1.Active then
if VideoRender1<>nil then
with VideoRender1 as IVideoWindowdo
begin
put_Owner(Panel1.Handle);
put_WindowStyle(WS_CHILD or WS_CLIPSIBLINGS);;
SetWindowPosition(0,0,320,240);
put_Visible(true);
put_Width(320);
put_Caption('win1');
put_MessageDrain(Panel1.Handle);
end;
if fg2.Active then
if VideoRender2<>nil then
with VideoRender2 as IVideoWindowdo
begin
put_Owner(Panel1.Handle);
put_WindowStyle(WS_CHILD or WS_CLIPSIBLINGS);;
SetWindowPosition(0,300,320,240);
put_Visible(true);
put_Width(320);
put_Height(240);
put_Caption('win2');
put_MessageDrain(Panel1.Handle);
end;
fg1.Play;
fg2.Play;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DSPack, DSUtil, ExtCtrls, DirectShow9, ActiveX;
type
TForm1 = class(TForm)
fg1: TFilterGraph;
fg2: TFilterGraph;
Button1: TButton;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
SG1, VideoRender1, AudioRender1,FSour1:IBaseFilter;
SG2, VideoRender2, AudioRender2,FSour2:IBaseFilter;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var MediaType : TMediaType;
begin
fg1.Active:=true;
CoCreateInstance(CLSID_VideoMixingRenderer,nil,CLSCTX_InPROC,IID_IBASEFilter,VideoRender1);
COCreateInstance(CLSID_AsyncReader,nil,CLSCTX_INPROC,IID_IBASEFilter,fsour1);
CoCreateInstance(CLSID_SampleGrabber,nil,CLSCTX_INPROC,IID_IBASEFilter,SG1);
CoCreateInstance(CLSID_DSoundRender,nil,CLSCTX_INPROC,IID_IBASEFilter,AudioRender1);
with fg1 as IFilterGraphdo
begin
addfilter(FSour1 as IBaseFilter,StringToOLEStr('dpfs1'));
addfilter(VideoRender1 as IBaseFilter,StringToOLEStr('dpvr1'));
addfilter(SG1 as IBaseFilter,StringToOLEStr('dpsg1'));
addfilter(AudioRender1 as IBaseFilter,StringToOLEStr('dpar1'));
end;
with FSour1 as IFileSourceFilterdo
Load(StringToOLEStr('f:/Hands_L.mpg'),nil);
MediaType:=TMediaType.Create(MEDIATYPE_Video);
MediaType.ResetFormatBuffer;
ZeroMemory(MediaType.AMMediaType,sizeof(TAMMediaType));
MediaType.MajorType:=MEDIATYPE_Video;
MediaType.SubType:=MEDIASUBTYPE_RGB32;
with SG1 as ISampleGrabberdo
SetMediaType(MediaType.AMMediaType^);
with fg1 as ICaptureGraphBuilder2do
begin
RenderStream(nil,nil,FSour1,SG1,VideoRender1);
RenderStream(nil,nil,FSour1,nil,AudioRender1);
end;
with SG1 as ISampleGrabberdo
SetBufferSamples(true);
MediaType.Free;
with fg1 as IMediaPositiondo
put_CurrentPosition(0);
fg2.Active:=False;
fg2.Active:=True;
Cocreateinstance(CLSID_VideoMixingRenderer,nil,CLSCTX_INPROC,IID_IBASEFilter,VideoRender2);
Cocreateinstance(CLSID_AsyncReader,nil,CLSCTX_INPROC,IID_IBASEFilter,fsour2);
Cocreateinstance(CLSID_SampleGrabber,nil,CLSCTX_INPROC,IID_IBASEFilter,SG2);
Cocreateinstance(CLSID_DSoundRender,nil,CLSCTX_INPROC,IID_IBASEFilter,AudioRender2);
with fg2 as IFilterGraphdo
begin
addfilter(FSour2 as IBaseFilter,StringToOLEStr('dpfs2'));
addfilter(VideoRender2 as IBaseFilter,StringToOLEStr('dpvr2'));
addfilter(SG2 as IBaseFilter,StringToOLEStr('dpsg2'));
addfilter(AudioRender2 as IBaseFilter,StringToOLEStr('dpar2'));
end;
with FSour2 as IFileSourceFilterdo
Load(StringToOLEStr('f:/Hands_R.mpg'),nil);
MediaType:=TmediaType.Create(MEDIATYPE_Video);
MediaType.ResetFormatBuffer;
ZeroMemory(MediaType.AMMediaType,sizeof(TAMMediaType));
MediaType.MajorType:=MEDIATYPE_Video;
MediaType.FormatType:=FORMAT_VideoInfo;
MediaType.SubType:=MEDIASUBTYPE_RGB32;
with SG2 as ISampleGrabberdo
SetMediaType(MediaType.AMMediaType^);
with fg2 as ICaptureGraphBuilder2do
begin
RenderStream(nil,nil,FSour2,SG2,VideoRender2);
RenderStream(nil,nil,FSour2,nil,AudioRender2);
end;
with fg2 as IMediaPositiondo
put_CurrentPosition(0);
if fg1.Active then
if VideoRender1<>nil then
with VideoRender1 as IVideoWindowdo
begin
put_Owner(Panel1.Handle);
put_WindowStyle(WS_CHILD or WS_CLIPSIBLINGS);;
SetWindowPosition(0,0,320,240);
put_Visible(true);
put_Width(320);
put_Caption('win1');
put_MessageDrain(Panel1.Handle);
end;
if fg2.Active then
if VideoRender2<>nil then
with VideoRender2 as IVideoWindowdo
begin
put_Owner(Panel1.Handle);
put_WindowStyle(WS_CHILD or WS_CLIPSIBLINGS);;
SetWindowPosition(0,300,320,240);
put_Visible(true);
put_Width(320);
put_Height(240);
put_Caption('win2');
put_MessageDrain(Panel1.Handle);
end;
fg1.Play;
fg2.Play;
end;
end.