快捷搜索:  汽车  科技

c c 的声音,C声音播放

c c 的声音,C声音播放声明[DllImport("winmm.dll")] private static extern uint mciSendString(string command StringBuilder returnValue int returnLength IntPtr winHandle);基本功能实现注意temp_alias 这个是对应别名

摘要

MCISendString 播放MP3

mci(Media Control Interface,媒体控制接口)函数中,有些只适用于一种接口方式,有些则两种接口都可以用。mciSendString只适用于命令串接口方式(命令串中不区分大小写)。

正文

声明

[DllImport("winmm.dll")] private static extern uint mciSendString(string command StringBuilder returnValue int returnLength IntPtr winHandle);

基本功能实现

注意temp_alias 这个是对应别名

/// <summary> /// 播放 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlay_Click(object sender EventArgs e) { StringBuilder path = new StringBuilder(); path.Append(@"D:\MyProject\白泽\Bz.Platform\wavplay\a.mp3"); mciSendString(@"close temp_alias" null 0 IntPtr.Zero); mciSendString(@"open """ path @""" alias temp_alias" null 0 IntPtr.Zero); mciSendString("play temp_alias repeat" null 0 IntPtr.Zero); } /// <summary> /// 停止 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStop_Click(object sender EventArgs e) { mciSendString("stop temp_alias" new StringBuilder() 0 IntPtr.Zero); } /// <summary> /// 暂停 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPause_Click(object sender EventArgs e) { mciSendString("pause temp_alias" new StringBuilder() 0 IntPtr.Zero); } /// <summary> /// 继续 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnResume_Click(object sender EventArgs e) { mciSendString("resume temp_alias" new StringBuilder() 0 IntPtr.Zero); } /// <summary> /// 取得音频长度 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLength_Click(object sender EventArgs e) { StringBuilder lengthBuf = new StringBuilder(32); mciSendString("status temp_alias length" lengthBuf lengthBuf.Capacity IntPtr.Zero); long len = long.Parse(lengthBuf.ToString()); MessageBox.Show((len / 1000.0f/60.0f).ToString()); } //调整声音1-1000 private void tbVoice_Scroll(object sender EventArgs e) { StringBuilder sb = new StringBuilder(32); sb.Append(tbVoice.Value.ToString()); mciSendString("setaudio temp_alias volume to " tbVoice.Value.ToString() sb sb.Capacity IntPtr.Zero); } /// <summary> /// 取得当前位置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCurrent_Click(object sender EventArgs e) { StringBuilder lengthBuf = new StringBuilder(32); mciSendString("status temp_alias position" lengthBuf lengthBuf.Capacity IntPtr.Zero); long len = long.Parse(lengthBuf.ToString()); MessageBox.Show((len / 1000.0f / 60.0f).ToString()); }

c c 的声音,C声音播放(1)

猜您喜欢: