1 Star 0 Fork 0

johntao/mir4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Mpeg.pas 3.31 KB
一键复制 编辑 原始数据 按行查看 历史
johntao 提交于 2024-05-12 15:47 . 新增声音模块
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.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/johntao/mir4.git
git@gitee.com:johntao/mir4.git
johntao
mir4
mir4
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385