我想在我的程序背景中播放mp3(例如,不打开媒体播放器 - > System.Diagnostics.Process.Start(@“C:\ Users \ Franz \ Music \ Americana.mp3”) (我不想用...)
现在我尝试了这样:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
class sound
{
[DllImport("winmm.dll")]
private static extern int mciSendString(string @cmd, StringBuilder ret, int retLen, IntPtr hwnd);
[DllImport("winmm.dll")]
private static extern int mciGetErrorString(int errCode, StringBuilder errText, int errLen);
}
private void txbStart_MouseClick(object sender, MouseEventArgs e)
{
mciSendString("play \""+C:\Users\Franz\Music\Americana.mp3+"\", null, 0, IntPtr.Zero);
}
但它不起作用?但为什么?我是c#的初学者......
答案 0 :(得分:0)
您可以使用许多不同的方法,其中一些方法如下所述: