1
根據我的朋友here最後一個職位建議這樣的代碼:如何在C#中重複MIDI文件?
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace TeaTimer
{
/// <summary>
/// MCIPlayer is based off code by Slain.
/// Found here: http://www.sadeveloper.net/Articles_View.aspx?articleID=212
/// </summary>
public class MCIPlayer
{
private static readonly string sAlias="TeaTimerAudio";
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
[DllImport("Winmm.dll")]
private static extern long PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);
public static void Play(string sFile)
{
_Open(sFile);
_Play();
}
public static void Stop()
{
_Close();
}
private static void _Open(string sFileName)
{
if(_Status()!="")
_Close();
string sCommand = "open \"" + sFileName + "\" alias "+sAlias;
mciSendString(sCommand, null, 0, IntPtr.Zero);
}
private static void _Close()
{
string sCommand = "close "+sAlias;
mciSendString(sCommand, null, 0, IntPtr.Zero);
}
private static void _Play()
{
string sCommand = "play "+sAlias;
mciSendString(sCommand, null, 0, IntPtr.Zero);
}
private static string _Status()
{
StringBuilder sBuffer = new StringBuilder(128);
mciSendString("status "+sAlias+" mode", sBuffer, sBuffer.Capacity, IntPtr.Zero);
return sBuffer.ToString();
}
}
}
它工作正常,但現在的問題是,我不能重複我的MIDI文件。 我看到了一些代碼,但我不知道爲什麼它不起作用。 我試過了:
Scommand = "play "+sAlias+" repeat ";
mciSendString(Scommand, null, 0, IntPtr.Zero);
我應該怎麼做重複2次以上plz幫助我:(( – Amir 2010-11-13 21:58:06
我有更多的一個問題,我用它在我的框架,我的意思是我有一個其他的框架,但在我關閉框架後,我的聲音盯着一段時間 – Amir 2010-11-13 22:01:59
@Amir你可以把一個變量存儲在歌曲重複的時間,並檢查WndProc()內的變量,以確定是否需要調用MCIPlayer。再次播放(文件) – 2017-06-20 16:20:11