动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 VB.NET中使用Directsound9之简单播放

作者来源: 
阅读 1197 人次 , 2006-4-20 9:22:00 

关于VB6的爱好者.大家还是尽快放弃VB6吧,我从97年开始用,现在终于也到了.Net了,中间的痛苦可想而知。尤其是服务器编程,.NET会方便很多。客户端随着XP的推广跟windows update的升级,也快了,别到时候别没有准备。

我的学习方法:

看SDK的文档,了解诸多概念,然后看SDK C#的教程(已经习惯了)

准备工作:

VS2003(有2002的,但是不用那个版本)

DXSDK 9.0C 2004 Dec(记住,是for VS2k3的,曾经有过VS2k2的,而且很多地方不通用)

Win2k(这个久不用说了吧)

主要步骤:

1、首先要添加引用.否则直接imports没办法找到 Microsoft.Directx....

2、引用完了,为了方便再imports Microsoft.DirectX.directsound

为了播放一个简单的声音文件进行如下操作:

·创建一个设备,关联到这个窗体

·创建一个缓冲,指定来源(这里用文件)

·播放...

Dim ad As Device '创建设备

Dim Buf As SecondaryBuffer '创建缓冲

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ad = New Device '实力化设备对象

ad.SetCooperativeLevel(Me.Handle, CooperativeLevel.Normal) '关联

Buf = New SecondaryBuffer("G:\MEDIA\WAV\ff9start.wav", ad) '实力化缓冲区

Buf.Play(0, BufferPlayFlags.Looping) '播放,同时指定开始位置跟方式

End Sub

这是一个最基本最简单的例子,目的是了解步骤。

有趣的现象,由于DS关联的是窗体,当窗体失去焦点的时候,他会停止播放 一旦重新获得焦点会继续播放。

很方便吧

但是DS用的是缓冲区的,在切换的时候,会丢失声音,少了那么一点,SDK也提到过,但是我没有认真看(1 感觉问题不大(除非录音) 2 英文的,懒~)

实际上没有必要解决丢失问题,因为对buf描述的时候就有这个选项。

普通的(就是默认的,我用的这种)

Sticky 看原文吧:Buffers with \"sticky\" focus will continue to play if the user switches to another application not using DirectSound. However, if the user switches to another DirectSound application, all normal-focus and sticky-focus buffers in the previous application are muted.";

全局的:Buffers with global focus will continue to play if the user switches focus to another application, even if the new application uses DirectSound. The one exception is if you switch focus to a DirectSound application that uses the DSSCL_WRITEPRIMARY cooperative level. In this case, the global-focus buffers from other applications will not be audible.";

再就是 默认 硬件加速 软件加速 (用默认就好,有硬件就用硬件,否则模拟)

以下是原文:

if (MixHardware)

{

sText = sText + "\n\nWith the hardware mixing flag, the new buffer will be forced to use hardware mixing. If the device does not support hardware mixing or if the required hardware resources are not available, the call to the DirectSound.CreateSoundBuffer method will fail.";

}

else if (MixSoftware)

{

sText = sText + "\n\nWith the software mixing flag, the new buffer will use software mixing, even if hardware resources are available.";

}

else

{

// Default mixing

sText = sText + "\n\nWith default mixing, the new buffer will use hardware mixing if available, otherwise software mixing will be used.";

}

由于内容很简单,没有翻译的必要(主要是因为懒,自己能看懂稍微记录一下就算了)

实际上DirectSound能作的工作很多,包括特效,3D音效跟混音以及声音抓取等。

  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:使用Web服务将C#代码转换为VB.NET代码
· 下一篇:深入浅出VB.NET提示对话框
· ASP.NET ViewState 初探 (3)
· ASP.NET创建XML Web服务全接触(13)
· ASP.NET中上传下载文件
· 在VB.NET中应用SQLDMO
· 利用.NET schema对象模型提高灵活性


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077