代码拉取完成,页面将自动刷新
unit Mpeg;
interface
uses
Winapi.Windows, Vcl.Controls, Winapi.ActiveX, DShow;
type
TMPEG = class
private
g_pGraphBuilder: IGraphBuilder;
g_pMediaControl: IMediaControl; // 播放狀態設置.
g_pMediaSeeking: IMediaSeeking; // 播放位置.
g_pAudioControl: IBasicAudio; // 音量/平衡設置.
g_pVideoWindow: IVideoWindow; //設置播放表單.
boInit: Boolean;
boPlay: Boolean;
sFileName: string;
MovieWindow: TWinControl;
function Init(): Boolean;
procedure Close();
{ Private declarations }
public
constructor Create(PlayWindow: TWinControl);
destructor Destroy; override;
function play(sFileName: string): Boolean;
procedure Pause();
procedure stop();
{ Public declarations }
end;
implementation
procedure TMPEG.Close;
begin
if Assigned(g_pMediaControl) then
g_pMediaControl.stop; // 釋放所有用到的介面。
if Assigned(g_pAudioControl) then
g_pAudioControl := nil;
if Assigned(g_pMediaSeeking) then
g_pMediaSeeking := nil;
if Assigned(g_pMediaControl) then
g_pMediaControl := nil;
if Assigned(g_pVideoWindow) then
g_pVideoWindow := nil;
if Assigned(g_pGraphBuilder) then
g_pGraphBuilder := nil;
CoUninitialize;
boInit := False;
end;
constructor TMPEG.Create(PlayWindow: TWinControl);
begin
MovieWindow := PlayWindow;
g_pGraphBuilder := nil;
g_pMediaControl := nil;
g_pMediaSeeking := nil;
g_pAudioControl := nil;
g_pVideoWindow := nil;
// boInit:=Init();
boInit := False;
end;
destructor TMPEG.Destroy;
begin
Close();
inherited;
end;
function TMPEG.Init: Boolean;
begin
Result := False; // 初始化COM介面
if failed(CoInitialize(nil)) then
Exit; // 創建DirectShow Graph
if failed(CoCreateInstance(TGUID(CLSID_FilterGraph), nil, CLSCTX_INPROC, TGUID(IID_IGraphBuilder), g_pGraphBuilder)) then
Exit; // 獲取IMediaControl 介面
if failed(g_pGraphBuilder.QueryInterface(IID_IMediaControl, g_pMediaControl)) then
Exit; // 獲取IMediaSeeking 介面
if failed(g_pGraphBuilder.QueryInterface(IID_IMediaSeeking, g_pMediaSeeking)) then
Exit; // 獲取IBasicAudio 介面
if failed(g_pGraphBuilder.QueryInterface(IID_IBasicAudio, g_pAudioControl)) then
Exit; // 獲取IVideowindow 介面
if failed(g_pGraphBuilder.QueryInterface(IID_IVideoWindow, g_pVideoWindow)) then
Exit; // 所有介面獲取成功 R
Result := True;
end;
procedure TMPEG.Pause;
begin
g_pMediaControl.Pause;
end;
function TMPEG.play(sFileName: string): Boolean;
var
_hr: Hresult;
wFile: array[0..(MAX_PATH * 2) - 1] of Char;
begin
Result := False;
boInit := Init();
MultiByteToWideChar(CP_ACP, 0, PAnsiChar(AnsiString(sFileName)), -1, @wFile, MAX_PATH); //轉換格式
_hr := g_pGraphBuilder.renderfile(@wFile, nil);
if failed(_hr) then
Exit;
if MovieWindow <> nil then
begin
g_pVideoWindow.put_Owner(MovieWindow.Handle);
g_pVideoWindow.put_windowstyle(WS_CHILD or WS_Clipsiblings);
g_pVideoWindow.SetWindowposition(0, 0, MovieWindow.Width, MovieWindow.Height); //播放的圖像爲整個panel1的ClientRect//
end;
// g_pVideoWindow.SetWindowposition(0, 0, MovieWindow.Width, MovieWindow.Handle); //播放的圖像爲整個panel1的ClientRect//
// g_pAudioControl.put_Volume(VOLUME_FULL);//設置爲最大音量
g_pMediaControl.Run;
boPlay := True;
end;
procedure TMPEG.stop;
begin
if not boInit then
Exit;
g_pMediaControl.stop;
Close();
end;
end.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。