Delphi播放音乐文件(50分)

  • 主题发起人 主题发起人 sssing
  • 开始时间 开始时间
S

sssing

Unregistered / Unconfirmed
GUEST, unregistred user!
例如,在delphi上面建立2个按钮,播放同目录下的1.mp3文件或者wav,总之是音乐的.
点击第一个按钮就播放1.mp3,点击第二个按钮就播放2.wav,不弹出任何播放的界面哦!
要怎么样实现呢?越详细越好,谢谢!
 
网上好像有这样的例子吧,简单的可以用dspack写,或者用mmtools写
QQ 87797301
 
啊,這麼簡單的問題.

QQ:9189374
 
var m_pVideo: IGraphBuilder;
MediaSeeking: IMediaSeeking;
MediaPosition: IMediaPosition;
Duration,CurrentPos : int64;
VideoWindow:IVideoWindow;
pControl : IMediaControl;
//用户命令接口,用来控制过滤器容器
pEvent : IMediaEvent;
//过滤器容器事件接口
hr : HRESULT;
Tmp,hour,min,Second : integer;
_wfile: array[0..MAX_PATH - 1] of wchar;
begin

CoCreateInstance(CLSID_FilterGraph, nil, CLSCTX_INPROC, IID_IGraphBuilder, m_pVideo);
m_pVideo.QueryInterface(IMediaControl, pControl);
m_pVideo.QueryInterface(IMediaEvent, pEvent);
m_pVideo.QueryInterface(IID_IMediaPosition, MediaPosition);
m_pVideo.QueryInterface(IID_IMediaSeeking, MediaSeeking);
MultiByteToWideChar(CP_ACP, 0, pChar(Opendialog1.FileName), -1, @_wfile, MAX_PATH);
hr := m_pVideo.RenderFile(_wfile,nil);
MediaSeeking.GetDuration(Duration);//得到总时间
Tmp := Trunc(Duration / 10000000);
min := Trunc(Tmp / 60) - hour * 60;;
min := Trunc(Tmp / 60);
Second := Trunc(Tmp mod 60);
TrackBar1.Max := Tmp;
//second
label1.Caption := Format('%.2d:%.2d:%.2d',[hour,min,Second]);
if HRESULT(hr) >= 0 then

begin

hr := pControl.Run();
Playing := true;
Button4.Enabled := true;
Button5.Enabled := true;
IsOver := false;
IsOpenFile := true;
Timer1.Enabled := true;
if HRESULT(hr) >= 0 then

begin

(m_pVideo as Ivideowindow).put_Owner(Panel1.handle);
(m_pVideo as IMediaPosition).get_StopTime(t);

(m_pVideo as IVideowindow).put_WindowStyle(GetWindowLong(Panel1.handle,GWL_STYLE) OR WS_CHILD OR WS_CLIPSIBLINGS);
(m_pVideo as IVideowindow).put_WindowStyle(GetWindowLong(Panel1.handle,GWL_STYLE));
(m_pVideo as IVideoWindow).SetWindowPosition(0,0,Panel1.width,Panel1.height);
end;

end;

end;
 
后退
顶部