How to play audio from resource

前端 未结 4 962
梦如初夏
梦如初夏 2020-12-20 21:32

I am trying to play audio from a resource using .NET Compact Framework. I added an audio file for the resource property in my application and am trying to use the below samp

相关标签:
4条回答
  • 2020-12-20 21:48

    I got the solution. This code is working very well in .NET Compact Framework:

    // Convert a byte array to a stream
    using (var audioStream = new MemoryStream(Properties.Resources.full_song_wav))
    {
        using (var player = new SoundPlayer(audioStream))
        {
            player.Play()
        }
    }
    
    0 讨论(0)
  • 2020-12-20 21:50

    This should work for you:

    Stream str = Properties.Resources.YourWaveSoundFile;
    SoundPlayer plyr = new SoundPlayer(str);
    plyr.Play();
    

    Make sure you have using System.Media above your namespace.

    0 讨论(0)
  • 2020-12-20 21:54
    Resources.ResourceManager.GetStream("nudgeSound", Resources.Culture);
    System.IO.Stream s = Resources.ResourceManager.GetStream("nudgeSound", Resources.Culture);
    SoundPlayer player = new SoundPlayer(s);
    player.Play();
    
    0 讨论(0)
  • 2020-12-20 22:13

    Try this:

    //I added the file as a audio resource in my project
    SoundPlayer player = new SoundPlayer(Properties.Resources.recycle);
    player.Play();
    

    I didn't try with .NET Compact Framework. But it is working for me in C#.

    0 讨论(0)
提交回复
热议问题