求教!在为C#窗体添加背景音乐时不报错,但没声音解决办法
求教!在为C#窗体添加背景音乐时不报错,但没声音
代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string strfulpath=@"明月几时有.wav"; //获得声音文件的绝对路径
SoundPlayer simpleSound = new SoundPlayer(strfulpath);
simpleSound.Play();
}
}
}
编译运行,系统不报错,但是要的声音没有,音乐格式也没有错误
------解决方案--------------------
string strfulpath=@"明月几时有.wav"; //获得声音文件的绝对路径
你这句也不是个绝对路径啊。。你这是个相对路径
SoundPlayer simpleSound = new SoundPlayer(strfulpath);
simpleSound.Load();
simpleSound.Play();
------解决方案--------------------
播放声音还有一种方法用 DllImport 引入 Winmm.dll
------解决方案--------------------
路径正确吗?
string path = Environment.Current()+"\\明月几时有.wav";
这样才对吧。。
------解决方案--------------------
代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string strfulpath=@"明月几时有.wav"; //获得声音文件的绝对路径
SoundPlayer simpleSound = new SoundPlayer(strfulpath);
simpleSound.Play();
}
}
}
编译运行,系统不报错,但是要的声音没有,音乐格式也没有错误
------解决方案--------------------
string strfulpath=@"明月几时有.wav"; //获得声音文件的绝对路径
你这句也不是个绝对路径啊。。你这是个相对路径
SoundPlayer simpleSound = new SoundPlayer(strfulpath);
simpleSound.Load();
simpleSound.Play();
------解决方案--------------------
播放声音还有一种方法用 DllImport 引入 Winmm.dll
------解决方案--------------------
路径正确吗?
string path = Environment.Current()+"\\明月几时有.wav";
这样才对吧。。
------解决方案--------------------