C#使用 mciSendString 函式播放音效问题

Lorna-Blog 2012-10-18 10:02:39

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;

using System.Runtime.InteropServices; // 命名空間提供各種支援COM Interop 和平台叫用服務的成員
namespace WindowsApplication17
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);

[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
/// <summary>
/// 使用mciSendString播放音樂
/// </summary>
/// <param name="name">檔案名稱</param>
/// <param name="command">命令</param>
private static void mciMusic(string name,string command)
{
StringBuilder shortpath = new StringBuilder();
int result = GetShortPathName(name, shortpath, shortpath.Capacity);
name = shortpath.ToString();
string buf = string.Empty;
mciSendString(command + " " + name, buf, buf.Length, 0); //播放
}
private void btnPlay_Click(object sender, EventArgs e)
{
// 播放
mciMusic(@"01.mp3", "play");
}
private void btnPause_Click(object sender, EventArgs e)
{
// 暫停
mciMusic(@"01.mp3", "pause");
}
private void btnStop_Click(object sender, EventArgs e)
{
// 停止
mciMusic(@"01.mp3", "stop");
}
}
}



最基本的功能实现了 请问怎样让音乐自动循环播放
...全文
265 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lorna-Blog 2012-10-18
  • 打赏
  • 举报
回复
求代码
Lorna-Blog 2012-10-18
  • 打赏
  • 举报
回复
额 不会啊。。。。。。。。。。。。。。。
bdmh 2012-10-18
  • 打赏
  • 举报
回复
http://baike.baidu.com/view/1622810.htm
这是那个函数的介绍,里面不是有可以获得位置和长度的方法吗,你可以根据位置和长度知道是否播放完毕
风之影子 2012-10-18
  • 打赏
  • 举报
回复
不会吧,播放都写出来了,不会循环播放吗?
Lorna-Blog 2012-10-18
  • 打赏
  • 举报
回复
有人吗 .................

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧