使用API函数mciSendString构成的媒体播放类Word文档下载推荐.docx
- 文档编号:17791844
- 上传时间:2022-12-10
- 格式:DOCX
- 页数:8
- 大小:15.77KB
使用API函数mciSendString构成的媒体播放类Word文档下载推荐.docx
《使用API函数mciSendString构成的媒体播放类Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《使用API函数mciSendString构成的媒体播放类Word文档下载推荐.docx(8页珍藏版)》请在冰豆网上搜索。
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Runtime.InteropServices;
namespace使用API函数mciSendString构成的媒体播放类
{
publicpartialclassForm1:
Form
{
stringpath;
publicForm1()
InitializeComponent();
}
clsMCImci=null;
privatevoidbutton1_Click(objectsender,EventArgse)
mci=newclsMCI();
mci.FileName=path;
this.progressBar1.Maximum=mci.Duration;
mci.play();
this.timer1.Enabled=true;
privatevoidbutton2_Click(objectsender,EventArgse)
if(mci==null)
else
this.timer1.Enabled=false;
mci.StopT();
privatevoidbutton3_Click(objectsender,EventArgse)
OpenFileDialogop=newOpenFileDialog();
if(op.ShowDialog()==DialogResult.OK)
path=op.FileName;
privatevoidForm1_Load(objectsender,EventArgse)
privatevoidtimer1_Tick(objectsender,EventArgse)
this.progressBar1.Value=mci.CurrentPosition;
if(mci.CurrentPosition==mci.Duration)
publicclassclsMCI
publicclsMCI()
//
//TODO:
在此处添加构造函数逻辑
//定义API函数使用的字符串变量
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=260)]
privatestringName="
"
;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=128)]
privatestringdurLength="
[MarshalAs(UnmanagedType.LPTStr,SizeConst=128)]
privatestringTemStr="
intilong;
//定义播放状态枚举变量
publicenumState
mPlaying=1,
mPuase=2,
mStop=3
};
//结构变量
publicstructstructMCI
publicboolbMut;
publicintiDur;
publicintiPos;
publicintiVol;
publicintiBal;
publicstringiName;
publicStatestate;
publicstructMCImc=newstructMCI();
///<
summary>
///取得播放文件属性
/summary>
publicstringFileName
get
returnmc.iName;
set
//ASCIIEncodingasc=newASCIIEncoding();
try
TemStr="
TemStr=TemStr.PadLeft(127,Convert.ToChar("
"
));
Name=Name.PadLeft(260,Convert.ToChar("
mc.iName=value;
ilong=APIClass.GetShortPathName(mc.iName,Name,Name.Length);
Name=GetCurrPath(Name);
//Name="
open"
+Convert.ToChar(34)+Name+Convert.ToChar(34)+"
aliasmedia"
Name="
ilong=APIClass.mciSendString("
closeall"
TemStr,TemStr.Length,0);
ilong=APIClass.mciSendString(Name,TemStr,TemStr.Length,0);
setmediatimeformatmilliseconds"
mc.state=State.mStop;
catch
MessageBox.Show("
出错错误!
);
///播放
publicvoidplay()
APIClass.mciSendString("
playmedia"
mc.state=State.mPlaying;
///停止
publicvoidStopT()
TemStr=TemStr.PadLeft(128,Convert.ToChar("
closemedia"
TemStr,128,0);
///
publicvoidPuase()
pausemedia"
mc.state=State.mPuase;
paramname="
name"
>
<
/param>
returns>
/returns>
privatestringGetCurrPath(stringname)
if(name.Length<
1)return"
name=name.Trim();
name=name.Substring(0,name.Length-1);
returnname;
///总时间
publicintDuration
durLength="
durLength=durLength.PadLeft(128,Convert.ToChar("
statusmedialength"
durLength,durLength.Length,0);
durLength=durLength.Trim();
if(durLength=="
)return0;
durLength=durLength.Substring(0,durLength.IndexOf('
\0'
return(int)(Convert.ToDouble(durLength)/1000f);
///当前时间
publicintCurrentPosition
statusmediaposition"
durLength=durLength.Substring(0,durLength.IndexOf('
mc.iPos=(int)(Convert.ToDouble(durLength)/1000f);
returnmc.iPos;
publicclassAPIClass
[DllImport("
kernel32.dll"
CharSet=CharSet.Auto)]
publicstaticexternintGetShortPathName(
stringlpszLongPath,
stringshortFile,
intcchBuffer
);
winmm.dll"
EntryPoint="
mciSendString"
publicstaticexternintmciSendString(
stringlpstrCommand,
stringlpstrReturnString,
intuReturnLength,
inthwndCallback
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 使用 API 函数 mciSendString 构成 媒体 播放