Пример использования DirectShow для просмотра фильмов на DVD


Компилятор: Borland Delphi 7 

Операционная система: Windows XP

Текст файла Project1.dpr

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.


Текст файла Unit1.pas

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;

type

TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
OpenDialog1: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses ActiveX, ComObj, DShow;

var
DvdGraphBuilder: IDvdGraphBuilder;
DvdControl: IDvdControl;
GraphBuilder: IGraphBuilder;
MediaControl: IMediaControl;

procedure TForm1.FormCreate(Sender: TObject);
begin
CoInitialize(nil)
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
CoUninitialize
end;

procedure PlayMediaDS(FileName: string);
var
DvdStatus: TAM_DVD_RenderStatus;
begin
if CoCreateInstance(CLSID_DvdGraphBuilder,nil,CLSCTX_INPROC_SERVER,
IID_IDvdGraphBuilder,DvdGraphBuilder)=S_OK then
if DvdGraphBuilder.RenderDvdVideoVolume(StringToOleStr(FileName),0,DvdStatus)=S_OK then
if DvdGraphBuilder.GetDvdInterface(IID_IDvdControl,DvdControl)=S_OK then
if DvdGraphBuilder.GetFiltergraph(GraphBuilder)=S_OK then
if GraphBuilder.QueryInterface(IID_IMediaControl,MediaControl)=S_OK then
MediaControl.Run
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then PlayMediaDS(OpenDialog1.FileName)
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
DvdControl.ButtonActivate
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
DvdControl.UpperButtonSelect
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
DvdControl.LowerButtonSelect
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
DvdControl.LeftButtonSelect
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
DvdControl.RightButtonSelect
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
DvdControl.MenuCall(DVD_MENU_Title)
end;

end.


Текст файла Uni1.dfm

object Form1: TForm1
Left = 709
Top = 112
Width = 241
Height = 117
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 4
Top = 4
Width = 53
Height = 25
Caption = #1060#1072#1081#1083
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 120
Top = 30
Width = 53
Height = 25
Caption = #1053#1072#1078#1072#1090#1100
TabOrder = 1
OnClick = Button2Click
end
object Button3: TButton
Left = 120
Top = 4
Width = 53
Height = 25
Caption = #1042#1074#1077#1088#1093
TabOrder = 2
OnClick = Button3Click
end
object Button4: TButton
Left = 120
Top = 56
Width = 53
Height = 25
Caption = #1042#1085#1080#1079
TabOrder = 3
OnClick = Button4Click
end
object Button5: TButton
Left = 64
Top = 30
Width = 53
Height = 25
Caption = #1042#1083#1077#1074#1086
TabOrder = 4
OnClick = Button5Click
end
object Button6: TButton
Left = 176
Top = 30
Width = 53
Height = 25
Caption = #1042#1087#1088#1072#1074#1086
TabOrder = 5
OnClick = Button6Click
end
object Button7: TButton
Left = 4
Top = 30
Width = 53
Height = 25
Caption = #1052#1077#1085#1102
TabOrder = 6
OnClick = Button7Click
end
object OpenDialog1: TOpenDialog
Filter = #1060#1080#1083#1100#1084#1099' '#1085#1072' DVD (*.ifo)|*.ifo'
Left = 4
Top = 56
end
end


загрузка файла: ds_dvd.exe (SFX-архив)

размер: 50 КБ



загрузка файла: dshow.exe (SFX-архив)

размер: 190 КБ