C# 播放嵌入式资源mp3文件

C# 播放嵌入式资源mp3文件,c#,winforms,mp3,embedded-resource,C#,Winforms,Mp3,Embedded Resource,我试图播放一个mp3文件,它嵌入到我的c#应用程序(winforms)中,但没有结果。我不想从资源创建文件并播放它。我在网上搜索过,但没有找到任何有效的例子。他们都在从资源创建一个文件并保存它,然后将文件路径传递给mci或wmp。有可能经过一条小溪吗 public partial class Form1 : Form { [DllImport("winmm.dll")] private static extern long mciSendString(string lpstrCo

我试图播放一个mp3文件,它嵌入到我的c#应用程序(winforms)中,但没有结果。我不想从资源创建文件并播放它。我在网上搜索过,但没有找到任何有效的例子。他们都在从资源创建一个文件并保存它,然后将文件路径传递给mci或wmp。有可能经过一条小溪吗

public partial class Form1 : Form
{
    [DllImport("winmm.dll")]
    private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
    public Form1()
    {
        InitializeComponent();
        Stream fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("mymp3.mp3");
        string command = "open" + fileStream not filePath + "type MPEGVideo alias MyMp3";
        mciSendString(command, null, 0, 0);
        command = "play MyMp3";
        mciSendString(command, null, 0, 0);
    }
}

提前感谢

您需要将MP3转换为可播放格式。您已经有了MP3流,因此可以使用NAudio之类的东西将其转换为WAV流。完成此操作后,可以使用SoundPlayer类。你会得到如下结果

using (Mp3FileReader reader = new Mp3FileReader(fileStream)) {  
    using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)) {   
        SoundPlayer player = new SoundPlayer(pcmStream);  
        player.Play();  
} } }

那么您打算如何使用此
文件流
?我已经更新了代码,我想使用流而不是文件路径。我想,这个命令不会是一个字符串。