播放声音 [英] PlaySound

查看:81
本文介绍了播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PlaySound上找到了相关信息。我在我的程序中实现了它

只是花花公子。唯一的小问题是我必须打包

..wav文件并发送它们,因为PlaySound播放声音文件。


其中一个选项我在PlaySound的一个很好的描述中发现,

还有其他几种选择。


1)声音可以在注册表中实际控制/选择

最终用户。


2)声音也可以嵌入到组件中,只要我可以指向

到包含声音的区域。


我不知道如何设置特定

应用程序的声音注册表。无论如何,wav文件必须安装在用户的

机器的某个地方,所以这似乎不是一个很好的方法。如果它是相当简单的话,我可能会这样做。


最好的似乎是以某种方式将wav嵌入应用程序并播放

内存中的副本。我的问题在于我不知道如何将wav的

内容放入应用程序中的可引用内存

位置。而且我不知道是否需要转换,因为我带来了

。文件中必须有一些提示,例如,多长时间

wav是。或者它可能是自定义的终止字节

序列 - 可能是全0或全Fs字。没有任何线索。


对后两种可能性的任何帮助都将不胜感激!


问候,

Ot

I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
..wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular
application. The wav files have to be installed somewhere on the user''s
machine anyway, so this doesn''t seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don''t know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot

推荐答案

*" Ot" < ur *** @ tds.invalid(使用网)> scripsit:
* "Ot" <ur***@tds.invalid (use net)> scripsit:
我在PlaySound上找到了相关信息。我在我的程序中实现了它,它只是花花公子。唯一的小问题是我必须打包
.wav文件并发送它们,因为PlaySound播放声音文件。

我在PlaySound的一个很好的描述中找到的选项之一说
还有其他几种选择。

1)声音可以在注册表中,并由最终用户实际控制/选择。

2)声音也可以嵌入到组件中,只要我能指向包含声音的区域。

我不知道如何设置注册表用于特定
应用程序的声音。无论如何,wav文件必须安装在用户机器的某个地方,所以这似乎不是一个很好的方法。如果它相当简单,我可能会这样做。

最好的似乎是以某种方式将wav嵌入到应用程序中并播放内存中的副本。我的问题是我不知道如何将wav的
内容放入可引用内存的应用程序中
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular
application. The wav files have to be installed somewhere on the user''s
machine anyway, so this doesn''t seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory




参见:


< http://groups.google.com/groups?selm = exQuKMjfDHA.1712%40TK2MSFTNGP11.phx.gb l>


-

Herfried K. Wagner [MVP]

< http://www.mvps.org/dotnet>



See:

<http://groups.google.com/groups?selm=exQuKMjfDHA.1712%40TK2MSFTNGP11.phx.gb l>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


将文件添加到您的应用程序并将其构建操作设置为

EmbeddedResource。您可以像这样引用它:

System.Reflection.Assembly.GetExecutingAssembly()。 GetManifestResourceStream(

" myWavFile.wav"))

" Ot" < ur *** @ tds.invalid(使用网)>在消息中写道

新闻:eN ************** @ TK2MSFTNGP09.phx.gbl ...
Add the file to your application and set it''s build action to
EmbeddedResource. You can reference it like this:
System.Reflection.Assembly.GetExecutingAssembly(). GetManifestResourceStream(
"myWavFile.wav"))
"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
我在PlaySound上找到了相关信息。我在我的程序中实现了它,它只是花花公子。唯一的小问题是我必须打包
.wav文件并发送它们,因为PlaySound播放声音文件。

我在PlaySound的一个很好的描述中找到的选项之一说
还有其他几种选择。

1)声音可以在注册表中,并由最终用户实际控制/选择。

2)声音也可以嵌入到组件中,只要我能指向包含声音的区域。

我不知道如何设置注册表对于
特定应用程序的声音。无论如何,wav文件必须安装在用户机器的某个地方,所以这似乎不是一个很好的方法。如果它相当简单,我可能会这样做。

最好的似乎是以某种方式将wav嵌入到应用程序中并播放内存中的副本。我的问题是我不知道如何将wav的
内容放入应用程序的可引用内存位置。而且我不知道是否需要进行任何转换,因为我带来了它。文件中必须有一些暗示,例如,wav有多长时间。或者它可能是自定义的终止字节序列 - 可能是全0或全Fs字。没有任何线索。

对后两种可能性的任何帮助都将不胜感激!

问候,
Ot
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular application. The wav files have to be installed somewhere on the user''s
machine anyway, so this doesn''t seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don''t know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot



OT,


我写了这个类(下面)来处理声音。也许你可以根据自己的需要修改它。


我之所以这样做是因为我必须制作自己的消息盒并且没有赢得''

哔声。你可以打电话给


PlaySoundFile传递一个wavefile的路径它会播放。


或者你可以调用系统声音之一这个


PlaySYSTEM_ASTERISK(在控制面板的

窗口声音中播放与Asterisk相关的任何内容。)


在您谈到时,有一种方法可以将自己的声音添加到控制面板。


**** MSDN ****

注册声音活动

您的应用程序可以注册用户可以分配的特定事件

声音文件。触发这些事件后,分配的声音文件将被播放。要注册声音事件,请在HKEY_CURRENT_USER

键下创建一个键,如下所示:

HKEY_CURRENT_USER


AppEvents


活动标签


EventName =活动名称


将EventName的值设置为a用户可以阅读的名称。这是

出现在控制面板中的内容。


注册声音事件使其在控制面板中可用,以便用户

可以为其分配声音文件。您的应用程序必须提供代码,以便

在适当时触发该事件。


为您的应用程序定义尽可能多的声音事件可以是

对需要额外反馈的用户特别有用 - 例如,

具有视觉和某些类型认知障碍的用户。这不是
意味着您的应用程序必须为所有事件生成声音。你可以

默认情况下不会将声音分配给某个事件。这样,想要

额外反馈的用户可以使用控制面板添加适当的声音。


始终使用注册表项指定要播放的声音。避免

按文件名或资源指定声音,因为这些不能通过控制面板定制,而且因为辅助功能无法确定其含义这些声音。


此外,在执行

等效操作时,始终会触发标准声音事件。例如,如果您显示等效的关键

消息框,请播放SND_ALIAS_SYSTEMEXCLAMATION事件声音。


更多信息


有关系统声音事件的更多信息,请参阅MSDN在线网站上的Microsoft平台

SDK
http://msdn.microsoft.com/ui/guide/sdk.asp


**** MSDN结束****

搜索无壳过滤与外壳集成....


HTH


Shane

Public Class clsSound


声明自动功能PlaySound Lib" winmm.dll" (ByVal名称_


As String,ByVal hmod As Integer,ByVal flags As Integer)As Integer


''name指定声音文件当设置了SND_FILENAME标志时。


''hmod指定一个可执行文件句柄。


''如果SND_RESOURCE标志,则hmod必须为Nothing未设置。


''标志指定设置了哪些标志。


''PlaySound文档列出了所有有效标志。


Public Const SND_SYNC =& H0''同步播放


Public Const SND_ASYNC =& H1''异步播放

Public Const SND_FILENAME =& H20000''名称是文件名


Public Const SND_RESOURCE =& H40004''名称是资源名称或原子


''私人助手方法播放系统声音同步或异步


BSYNC hronous As Boolean)


如果bSynchronous那么


PlaySound(strSystemSound,0,SND_SYNC)


Else


PlaySound(strSystemSound,0,SND_ASYNC)


结束如果


End Sub


公共共享子PlaySoundFile(ByVal文件名为字符串)


''从文件名播放声音。


PlaySound(文件名,无,SND_FILENAME或SND_ASYNC)

结束子


公共共享子PlaySYSTEM_ASTERISK(可选ByVal bSynchronous As Boolean

=假)


PlaySystemSound(SystemAsterisk,bSynchronous)


End Sub


公共共享子PlaySYSTEM_EXCLAMATION(可选ByVal bSynchronous As

布尔值= False)


PlaySystemSound(SystemExclamation,bSynchronous)


End Sub


公共共享子PlaySYSTEM_EXIT(可选ByVal bSynchronous As Boolean =

False)


PlaySystemSound(" SystemExit",bSynchronous)

End Sub

公共共享子PlaySYSTEM_HAND(可选ByVal bSynchronous As Boolean =

False)


PlaySystemSound(" SystemHand",bSynchronous )


End Sub


公共共享子PlaySYSTEM_QUESTION(可选ByVal bSynchronous As Boolean

= False)


PlaySystemSound(" SystemQuestion",bSynchronous)

结束子


公共共享子PlaySYSTEM_START(可选ByVal bSynchronous As Boolean =

False)


PlaySystemSound(SystemStart,bSynchronous)


结束Sub


结束班


" Ot" < ur *** @ tds.invalid(使用网)>在消息中写道

新闻:eN ************** @ TK2MSFTNGP09.phx.gbl ...
OT,

I wrote this class (below), to handle sound. Maybe you can modify it for
your own needs.

I made this because I had to make my own messsage box and didn''t won''t the
beep sound. You can call

PlaySoundFile passing a wavefile''s path and it will play.

or you can call one of the system sounds like this

PlaySYSTEM_ASTERISK (this plays whatever is associated with Asterisk in the
windows sounds in control panel.)

There is a way to add your own sounds to the control panel as you spoke of.

****MSDN****
Registering Sound Events
Your application can register specific events to which the user can assign
sound files. When those events are triggered, the assigned sound file is
played. To register a sound event, create a key under the HKEY_CURRENT_USER
key, as follows:

HKEY_CURRENT_USER

AppEvents

Event Labels

EventName = Event Name

Set the value for EventName to a name that users can read. This is what will
appear in Control Panel.

Registering a sound event makes it available in Control Panel so that users
can assign a sound file to it. Your application must provide the code to
trigger that event when appropriate.

Defining as many sound events as possible for your application can be
especially helpful for users who need additional feedback - for example,
users with visual and some types of cognitive impairments. This does not
mean that your application must generate sounds for all events. You can
simply not assign sounds to an event by default. This way, users who want
additional feedback can use Control Panel to add appropriate sounds.

Always specify sounds to be played by using registry entries. Avoid
specifying sounds by file name or resource, because these cannot be
customized through Control Panel, and because accessibility aids cannot
determine the meaning of these sounds.

In addition, always trigger standard sound events when carrying out
equivalent actions. For example, if you display the equivalent of a critical
message box, play the SND_ALIAS_SYSTEMEXCLAMATION event sound.

More Information

For more information about system sound events, see the Microsoft Platform
SDK on the MSDN Online Web site at
http://msdn.microsoft.com/ui/guide/sdk.asp.

****end of MSDN****
search for Integrating With the Shell with no filtering....

HTH

Shane
Public Class clsSound

Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _

As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

'' name specifies the sound file when the SND_FILENAME flag is set.

'' hmod specifies an executable file handle.

'' hmod must be Nothing if the SND_RESOURCE flag is not set.

'' flags specifies which flags are set.

'' The PlaySound documentation lists all valid flags.

Public Const SND_SYNC = &H0 '' play synchronously

Public Const SND_ASYNC = &H1 '' play asynchronously

Public Const SND_FILENAME = &H20000 '' name is file name

Public Const SND_RESOURCE = &H40004 '' name is resource name or atom

''private helper method to play system sound synch or async

Private Shared Sub PlaySystemSound(ByVal strSystemSound As String, ByVal
bSynchronous As Boolean)

If bSynchronous Then

PlaySound(strSystemSound, 0, SND_SYNC)

Else

PlaySound(strSystemSound, 0, SND_ASYNC)

End If

End Sub

Public Shared Sub PlaySoundFile(ByVal filename As String)

'' Plays a sound from filename.

PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)

End Sub

Public Shared Sub PlaySYSTEM_ASTERISK(Optional ByVal bSynchronous As Boolean
= False)

PlaySystemSound("SystemAsterisk", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_EXCLAMATION(Optional ByVal bSynchronous As
Boolean = False)

PlaySystemSound("SystemExclamation", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_EXIT(Optional ByVal bSynchronous As Boolean =
False)

PlaySystemSound("SystemExit", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_HAND(Optional ByVal bSynchronous As Boolean =
False)

PlaySystemSound("SystemHand", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_QUESTION(Optional ByVal bSynchronous As Boolean
= False)

PlaySystemSound("SystemQuestion", bSynchronous)

End Sub

Public Shared Sub PlaySYSTEM_START(Optional ByVal bSynchronous As Boolean =
False)

PlaySystemSound("SystemStart", bSynchronous)

End Sub

End Class

"Ot" <ur***@tds.invalid (use net)> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
我在PlaySound上找到了相关信息。我在我的程序中实现了它,它只是花花公子。唯一的小问题是我必须打包
.wav文件并发送它们,因为PlaySound播放声音文件。

我在PlaySound的一个很好的描述中找到的选项之一说
还有其他几种选择。

1)声音可以在注册表中,并由最终用户实际控制/选择。

2)声音也可以嵌入到组件中,只要我能指向包含声音的区域。

我不知道如何设置注册表对于
特定应用程序的声音。无论如何,wav文件必须安装在用户机器的某个地方,所以这似乎不是一个很好的方法。如果它相当简单,我可能会这样做。

最好的似乎是以某种方式将wav嵌入到应用程序中并播放内存中的副本。我的问题是我不知道如何将wav的
内容放入应用程序的可引用内存位置。而且我不知道是否需要进行任何转换,因为我带来了它。文件中必须有一些暗示,例如,wav有多长时间。或者它可能是自定义的终止字节序列 - 可能是全0或全Fs字。没有任何线索。

对后两种可能性的任何帮助都将不胜感激!

问候,
Ot
I found information on PlaySound. I implemented it in my program and it
works just dandy. The only little problem is that I have to package the
.wav files and send them along since PlaySound plays a sound file.

One of the options I found in a nice description of PlaySound says that
there are a couple of other choices.

1) The sound can be in the registry and actually controlled/selected by
the end user.

2) The sound can also be embedded in the assembly as long as I can point
to the area containing the sound.

I have no clue as to how to set up the registry for sounds for a particular application. The wav files have to be installed somewhere on the user''s
machine anyway, so this doesn''t seem a really great way to go. If it is
fairly simple I might do it anyway.

The best seems to be to embed the wav in the application somehow and play
the in-memory copy. My problem here is I have no idea how to get the
contents of the wav into the application at a referenceable memory
location. And I don''t know if there is any conversion required as I bring
it in. There must be some hint in the file as to, for example, how long
the wav is. Or maybe it is self defining with a termination byte
sequence -- maybe an all 0s or all Fs word. No clue.

Any help on the latter two possibilities would be appreciated!

Regards,
Ot








这篇关于播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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