惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Heimdal Security Blog
A
Arctic Wolf
K
Kaspersky official blog
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
MongoDB | Blog
MongoDB | Blog
T
Threat Research - Cisco Blogs
D
Docker
爱范儿
爱范儿
T
Tenable Blog
C
Check Point Blog
B
Blog
C
Cisco Blogs
Vercel News
Vercel News
The Cloudflare Blog
T
Threatpost
NISL@THU
NISL@THU
T
Tor Project blog
V2EX - 技术
V2EX - 技术
P
Palo Alto Networks Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tailwind CSS Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
SecWiki News
SecWiki News
博客园 - 司徒正美
S
Security @ Cisco Blogs
GbyAI
GbyAI
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Cloudbric
Cloudbric
Webroot Blog
Webroot Blog
N
News and Events Feed by Topic
Y
Y Combinator Blog
博客园_首页
T
Troy Hunt's Blog
The Hacker News
The Hacker News
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
U
Unit 42
AWS News Blog
AWS News Blog
PCI Perspectives
PCI Perspectives
V
Visual Studio Blog
博客园 - 聂微东
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 落木

PowerDesigner中NAME和COMMENT的互相转换,需要执行语句 获取网站根目录的urli源代码 - 落木 - 博客园 Control的Invoke和BeginInvoke 扩大范围的多条件查询 用.net的GetCallbackEventReference函数来实现dropDownList联动的ajax效果 处理SQLSERVER死锁(转载) 调用DirectX进行简单的多媒体编程系列(四) 调用DirectX进行简单的多媒体编程系列(三) 调用DirectX进行简单的多媒体编程系列(二) 数据库分页算法 mysql想说爱你不容易啊,从mssql迁移到mysql时,几乎所有的存储过程都得改,语法相差很大,累人!! 自己写的sqlserver和mysql的行转列通用存储过程 MSSQL优化文章 C#中编写sqlserver中自定义函数,实现复杂报表 Ajax使用Post方式提交到.aspx页面交互的例子 核单台帐表(存储过程) 清欠率(存储过程) ExtJS中的面向对象设计,组件化编程思想 - 落木 - 博客园 ExtJS中如何扩展自定义的类
调用DirectX进行简单的多媒体编程系列(一)
落木 · 2009-12-04 · via 博客园 - 落木

  最近的项目中,要做这样一个功能,在服务器上可以通过播放器针对不同的音箱设备来播放不同的音乐,就像大学里英语角一样,校广播台对不同的活动中心播放的不同的英文广播。当然我们的项目功能类似,但是却也没校园广播那么复杂,校园广播使用了很好的音频设备,我们得控制成本,所以我们的解决方案是:在服务器上安装一块多通道的专业声卡(录音棚用来录音)或者是安装多块普通的声卡。这样我们在播放音乐的时候可以选择输出的声卡,播放界面如下:

如何去做这样一个播放器呢,.net framework中是不是有这个接口,网上找了一下资料,发现有两种方法.

第一种方法是调用win32下的winmm.dllAPI函数去播放文件,代码:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace HardWaresOperation
{
    
public class SpeakerBeeper
    {
        
//文件资源
        private string SoundSource = @"C:\Documents and Settings\Administrator\桌面\gc22002a.wav";
        
private string SoundSource;
        
public SpeakerBeeper(string _SoundSource)
        {
            SoundSource 
= _SoundSource;
        }
        
/// <summary>
        
/// 检查声卡,播放声音
        
/// </summary>
        
/// <param name="_SoundSource">声音文件</param>
        
/// <returns>播放成功,返回true</returns>
        public bool SpeakerBeep()
        {
            
if (SBHelper.waveOutGetNumDevs() != 0)
            {
                SBHelper.PlaySound(SoundSource, IntPtr.Zero, SBHelper.PlaySoundFlags.SND_FILENAME 
| SBHelper.PlaySoundFlags.SND_ASYNC);
                
return true;
            }
            
else
            {
                
return false;
            }
        }
    }
    
// 这是辅助的文件SBHelper.cs
    public class SBHelper
    {
        
public enum PlaySoundFlags : int
        {
            SND_SYNC 
= 0x0000,//同步
            SND_ASYNC = 0x0001,//异步
            SND_NODEFAULT = 0x0002,//未找到文件默认为静音
            SND_MEMORY = 0x0004,//声音文件来自内存
            SND_LOOP = 0x0008//循环播放
            SND_NOSTOP = 0x0010,//不停止目前的播放
            SND_NOWAIT = 0x00002000,//当播放器忙碌时不等待
            SND_ALIAS = 0x00010000//为已注册的别名时
            SND_ALIAS_ID = 0x00110000//别名为ID
            SND_FILENAME = 0x00020000//文件名
            SND_RESOURCE = 0x00040004 //资源名
        }

        [DllImport(

"winmm.dll", EntryPoint = "waveOutGetNumDevs")]
        
//waveOutGetNumdevs()方法
        
//当机器有声卡时返回1
        
//没有声卡返回0
        public static extern int waveOutGetNumDevs();

        [DllImport(

"winmm.dll")]
        
//SoundSource声音文件
        
//参数hmod是应用程序的实例句柄
        
//psFlag播放模式
        public static extern bool PlaySound(string SoundSource, IntPtr hmod, PlaySoundFlags psFlag);

    }
}

但是发现waveOutGetNumDevs()函数只是用来返回机器是否有声卡,并没有得到机器的声卡设备的列表,知识对当前默认的设备进行播放,达不到要求。