I want to play a mp3 in background of my program ( without opening the media player for example --> System.Diagnostics.Process.Start(@"C:\Users\Franz\Music\Americana.mp3") ( I don't want to use...)
Now i tried it like this:
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);
}
But it doesn'T work? but why? I'm a beginner in c# ...
There are many different methods you could use, some of which are explained below: