积极答复者
调用api的问题。help~!

问题
-
为什么只能播一条mp3,但是我设个断点按着F10一步步执行就能全部的都播放?
知道什么问题了,就是foreach很快。
我要想全部播怎么办?难道要让线程休眠一会?但是也不行啊。。。。。
#region 点击试听 播放MP3
private void ie语音_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (1 == e.Button.Index)
{
string mp3 = "";
DevExpress.XtraEditors.MemoExEdit mee = sender as DevExpress.XtraEditors.MemoExEdit;
foreach (string str in mee.Lines)
{
mp3 = @"E:\原始语音\test\" + str;
MP3API.Sound.Play(mp3);
}}
}
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Security.Cryptography;namespace MP3API
{
public class APIClass
{
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int mciSendString(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
);[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
string path,
string shortPath,
int shortPathLength
);[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);public static string IniReadValue(string Section, string Key, string path)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
}
public class Sound
{
public static void Play(string fname)
{
string TemStr = "";
string shortName = "";
TemStr = TemStr.PadLeft(127, Convert.ToChar(" "));
shortName = shortName.PadLeft(260, Convert.ToChar(" "));
APIClass.mciSendString("close all", TemStr, TemStr.Length, 0);
if (!File.Exists(fname))
{
MessageBox.Show("无法找到语音文件[" + fname + "],请设置语音文件位置!", "无法找到语音文件", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
APIClass.GetShortPathName(fname, shortName, shortName.Length);
APIClass.mciSendString("play " + shortName, TemStr, TemStr.Length, 0);
}//关闭
public static void Stop()
{
APIClass.mciSendString("close media", "", 0, 0);
}
//暂停
public static void Pause()
{
APIClass.mciSendString("pause media", "", 0, 0);
}
}
}
答案
-
应该是同步的,如果是异步一起放10首那不就成噪音了
知识改变命运,奋斗成就人生!- 已标记为答案 KeFang Chen 2009年5月4日 3:56
全部回复
-
这是由于你打开另一首歌的时候首先关了上一首歌,你可以在调用 Play 之前加上 Thread.Sleep(5000)试试, 或者查查 API 是否提供了检查已播完的方法
知识改变命运,奋斗成就人生!- 已编辑 肖小勇Moderator 2009年4月28日 13:09
-
应该是同步的,如果是异步一起放10首那不就成噪音了
知识改变命运,奋斗成就人生!- 已标记为答案 KeFang Chen 2009年5月4日 3:56