MpgPlay.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:2k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "MpgPlay.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TMpgForm *MpgForm;
- //---------------------------------------------------------------------------
- __fastcall TMpgForm::TMpgForm(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TMpgForm::FormCreate(TObject *Sender)
- {
- BitBtn1->Enabled=true;
- BitBtn2->Enabled=false;
- Timer1->Enabled=false;
- //设置控件有效状态
- }
- //---------------------------------------------------------------------------
- void __fastcall TMpgForm::BitBtn1Click(TObject *Sender)
- {
- OpenDialog1->Title="请选择一个影碟文件:";
- //设置对话框标题
- OpenDialog1->Filter="电影文件(*.avi)|*.avi|电影文件(*.dat)|*.dat";
- //设置文件过滤器
- OpenDialog1->Execute();
- //显示对话框
- if(OpenDialog1->FileName!="")
- {
- MediaPlayer1->Display=Panel1;
- //设置视频文件的显示范围在显示区内
- MediaPlayer1->FileName=OpenDialog1->FileName;
- //设置文件的路径和文件名
- MediaPlayer1->Open();
- //打开多媒体设备
- Timer1->Enabled=true;
- BitBtn2->Enabled=true;
- //设置按钮有效状态
- ScrollBar1->Min=0;
- ScrollBar1->Max=MediaPlayer1->Length;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TMpgForm::BitBtn2Click(TObject *Sender)
- {
- MediaPlayer1->Stop();
- //停止播放
- MpgForm->Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMpgForm::ScrollBar1Scroll(TObject *Sender,
- TScrollCode ScrollCode, int &ScrollPos)
- {
- MediaPlayer1->Position=ScrollBar1->Position;
- //改变播放进度
- Timer1->Enabled=true;
- MediaPlayer1->Play();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMpgForm::Timer1Timer(TObject *Sender)
- {
- ScrollBar1->Enabled=true;
- ScrollBar1->Position=MediaPlayer1->Position;
- //显示播放进度
- }
- //---------------------------------------------------------------------------