如何实现ASP.NET中将声音文件添加到资源中并进行播放

本篇内容介绍了“如何实现ASP.NET中将声音文件添加到资源中并进行播放”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

具体如下:

1. 添加资源的方法如下:

如何实现ASP.NET中将声音文件添加到资源中并进行播放

2. Form2.cs如下:

//
// Any source code blocks look like this
//
using System.Reflection;
using System.IO;
using System.Resources;
using System.Media;
using System.Diagnostics;
namespace Yournamespace
{
 public partial class Form2 : Form
 {
  public Form2()
  {
   InitializeComponent();
  }
  private void Form2_Load(object sender, EventArgs e)
  {
   Assembly assembly;
   Stream soundStream;
   SoundPlayer sp;
   assembly = Assembly.GetExecutingAssembly();
   sp = new SoundPlayer(assembly.GetManifestResourceStream("Yournamespace.Dreamer.wav"));
   sp.Play(); 
  }
 }
}
/*SoundPlayer sp = new SoundPlayer(global::WindowsApplication1.Properties.Resources.yoursoundfilename); */

“如何实现ASP.NET中将声音文件添加到资源中并进行播放”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!