如何播放存储在数据库Access中的声音文件 [英] How to play a sound file stocked in a data base Access

查看:256
本文介绍了如何播放存储在数据库Access中的声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

请给我可以让我读取存储在数据库中的file.wav("alarme.wav")的代码,我尝试了以下代码:

Hello

Please can you give me the code that allows me to read a file.wav ("alarme.wav") stored in a database, I tried the following code:

private void button1_Click (object sender, EventArgs e)
{

OdbcConnection cn = new OdbcConnection ("DSN = cp1");
cn.Open ();
OdbcCommand cmd1 = new OdbcCommand ("select path from WHERE Code Alarm alarm = 32 ", cn);
cmd1.Connection = cn;
fileName = cmd1.ToString ();
WaveOut wave = new ();
wave.DeviceNumber = 0;
playSound (0);



但这给了我以下错误:
找不到文件"C:\ Users \ wafa \ Documents \ Visual Studio 2010 \ Projects \ ALARMED \ ALARMED \ bin \ Debug \ System.Data.Odbc.OdbcCommand"."
在此行:
"waveReader =新的NAudio.Wave.WaveFileReader(fileName);"在我的"playSound"函数中:



But that gave me the following error:
"Could not find file ''C: \ Users \ wafa \ Documents \ Visual Studio 2010 \ Projects \ ALARMED \ ALARMED \ bin \ Debug \ System.Data.Odbc.OdbcCommand''."
At the line:
"waveReader = new NAudio.Wave.WaveFileReader (fileName);" in my "playSound" function:

public void PlaySound (int deviceNumber)
{
disposeWave ();// stop previous sounds Before Starting
waveReader = new NAudio.Wave.WaveFileReader (fileName);
var waveOut NAudio.Wave.WaveOut = new ();
waveOut.DeviceNumber = deviceNumber;
var output = waveOut;
output.Init (waveReader);
output.Play ();
}



提前谢谢您.
美好的一天:)



Thank you in advance.
Good day:)

推荐答案

您在做什么?
这是错误的:fileName = cmd1.ToString ();

您需要通过命令运行查询,然后取回数据.从该数据中找到路径,然后使用它来播放文件.

您需要先阅读如何使用ADO.NET,然后再开始使用ADO.NET进行编码.
在这里阅读有关ADO.NET的信息,它将对您有所帮助.
看看这些:
MSDN:ADO.NET [ MSDN:使用ADO.NET访问数据 [ ^ ]
C#Station ADO.NET教程 [为初学者使用ADO.NET [
What are you doing?
This is wrong: fileName = cmd1.ToString ();

You need to run the query via command and then get the data back. From that data find the path and then use it to play the file.

You need to first read on how to use ADO.NET and then start coding for the same.
Read about ADO.NET here and it will help you.
Look at these:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]
The C# Station ADO.NET Tutorial[^]
Using ADO.NET for beginners[^]


因此,我可以更改此ligne吗???? ????
So ow can I change this ligne please?????????


这篇关于如何播放存储在数据库Access中的声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆