unit UMute;
interface
uses MMSystem, Dialogs;
Type
  TDeviceName = (Master, Microphone, WaveOut, Synth);
function  GetVolume(DN:TDeviceName) : Word ;
procedure SetVolume(DN:TDeviceName; Value:Word);
function  GetVolumeMute(DN:TDeviceName) : Boolean;
procedure  SetVolumeMute(DN:TDeviceName; Value:Boolean);
implementation
//获取音量
function GetVolume(DN:TDeviceName) : Word;
var
  hMix: HMIXER;
  mxlc: MIXERLINECONTROLS;
  mxcd: TMIXERCONTROLDETAILS;
  vol: TMIXERCONTROLDETAILS_UNSIGNED;
  mxc: MIXERCONTROL;
  mxl: TMixerLine;
  intRet: Integer;
  nMixerDevs: Integer;
begin
  Result:=;
  // Check if Mixer is available
  nMixerDevs := mixerGetNumDevs();
  if (nMixerDevs < ) then Exit;
  // open the mixer
  intRet := mixerOpen(@hMix, , , , );
  if intRet = MMSYSERR_NOERROR then begin
    case DN of
      Master     :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
      Microphone :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
      WaveOut    : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
      Synth      :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
    end;
    mxl.cbStruct := SizeOf(mxl);
    // get line info
    intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
    if intRet = MMSYSERR_NOERROR then begin
      FillChar(mxlc, SizeOf(mxlc),);
      mxlc.cbStruct := SizeOf(mxlc);
      mxlc.dwLineID := mxl.dwLineID;
      mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
      mxlc.cControls := ;
      mxlc.cbmxctrl := SizeOf(mxc);
      mxlc.pamxctrl := @mxc;
      intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
      if intRet = MMSYSERR_NOERROR then begin
        FillChar(mxcd, SizeOf(mxcd),);
        mxcd.dwControlID := mxc.dwControlID;
        mxcd.cbStruct := SizeOf(mxcd);
        mxcd.cMultipleItems := ;
        mxcd.cbDetails := SizeOf(Vol);
        mxcd.paDetails := @vol;
        mxcd.cChannels := ;
        intRet := mixerGetControlDetails(hMix, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
        Result := vol.dwValue ;
        if intRet <> MMSYSERR_NOERROR then
          ShowMessage('GetControlDetails Error');
      end else
        ShowMessage('GetLineInfo Error');
    end;
    mixerClose(hMix);
  end;
end;
//设置音量
procedure setVolume(DN:TDeviceName; Value : Word);
var
  hMix: HMIXER;
  mxlc: MIXERLINECONTROLS;
  mxcd: TMIXERCONTROLDETAILS;
  vol: TMIXERCONTROLDETAILS_UNSIGNED;
  mxc: MIXERCONTROL;
  mxl: TMixerLine;
  intRet: Integer;
  nMixerDevs: Integer;
begin
  // Check if Mixer is available
  nMixerDevs := mixerGetNumDevs();
  if (nMixerDevs < ) then Exit;
  // open the mixer
  intRet := mixerOpen(@hMix, , , , );
  if intRet = MMSYSERR_NOERROR then begin
    case DN of
      Master     : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
      Microphone : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
      WaveOut    : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
      Synth      : mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
    end;
    mxl.cbStruct := SizeOf(mxl);
    // get line info
    intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
    if intRet = MMSYSERR_NOERROR then begin
      FillChar(mxlc, SizeOf(mxlc),);
      mxlc.cbStruct := SizeOf(mxlc);
      mxlc.dwLineID := mxl.dwLineID;
      mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
      mxlc.cControls := ;
      mxlc.cbmxctrl := SizeOf(mxc);
      mxlc.pamxctrl := @mxc;
      intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
      if intRet = MMSYSERR_NOERROR then begin
        FillChar(mxcd, SizeOf(mxcd),);
        mxcd.dwControlID := mxc.dwControlID;
        mxcd.cbStruct := SizeOf(mxcd);
        mxcd.cMultipleItems := ;
        mxcd.cbDetails := SizeOf(Vol);
        mxcd.paDetails := @vol;
        mxcd.cChannels := ;
        vol.dwValue := Value;
        intRet := mixerSetControlDetails(hMix, @mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
        if intRet <> MMSYSERR_NOERROR then
          ShowMessage('SetControlDetails Error');
      end else
        ShowMessage('GetLineInfo Error');
    end;
    mixerClose(hMix);
  end;
end;
//获取静音
function  GetVolumeMute(DN:TDeviceName) : Boolean;
var
  hMix: HMIXER;
  mxlc: MIXERLINECONTROLS;
  mxcd: TMIXERCONTROLDETAILS;
  mxc: MIXERCONTROL;
  mxl: TMixerLine;
  intRet: Integer;
  nMixerDevs: Integer;
  mcdMute: MIXERCONTROLDETAILS_BOOLEAN;
begin
  // Check if Mixer is available
  nMixerDevs := mixerGetNumDevs();
  Result:=False;
  if (nMixerDevs < ) then Exit;
  // open the mixer
  intRet := mixerOpen(@hMix, , , , );
  if intRet = MMSYSERR_NOERROR then begin
    case DN of
      Master     :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
      Microphone :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
      WaveOut    :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
      Synth      :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
    end;
    mxl.cbStruct        := SizeOf(mxl);
    // mixerline info
    intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
    if intRet = MMSYSERR_NOERROR then begin
      FillChar(mxlc, SizeOf(mxlc),);
      mxlc.cbStruct := SizeOf(mxlc);
      mxlc.dwLineID := mxl.dwLineID;
      mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
      mxlc.cControls := ;
      mxlc.cbmxctrl := SizeOf(mxc);
      mxlc.pamxctrl := @mxc;
      // Get the mute control
      intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
      if intRet = MMSYSERR_NOERROR then begin
        FillChar(mxcd, SizeOf(mxcd),);
        mxcd.cbStruct := SizeOf(TMIXERCONTROLDETAILS);
        mxcd.dwControlID := mxc.dwControlID;
        mxcd.cChannels := ;
        mxcd.cbDetails := SizeOf(MIXERCONTROLDETAILS_BOOLEAN);
        mxcd.paDetails := @mcdMute;
        // Get  mute
        intRet := mixerGetControlDetails(hMix, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
        if mcdMute.fValue =  then
          Result:=false
        else
          Result := True;
        if intRet <> MMSYSERR_NOERROR then
          ShowMessage('SetControlDetails Error');
      end else
       ShowMessage('GetLineInfo Error');
    end;
  end;
end;
//获取静音
procedure  SetVolumeMute(DN:TDeviceName; Value:Boolean);
var
  hMix: HMIXER;
  mxlc: MIXERLINECONTROLS;
  mxcd: TMIXERCONTROLDETAILS;
  mxc: MIXERCONTROL;
  mxl: TMixerLine;
  intRet: Integer;
  nMixerDevs: Integer;
  mcdMute: MIXERCONTROLDETAILS_BOOLEAN;
begin
  // Check if Mixer is available
  nMixerDevs := mixerGetNumDevs();
  if (nMixerDevs < ) then Exit;
  // open the mixer
  intRet := mixerOpen(@hMix, , , , );
  if intRet = MMSYSERR_NOERROR then begin
    case DN of
      Master     :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
      Microphone :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
      WaveOut    :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
      Synth      :  mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
    end;
    mxl.cbStruct        := SizeOf(mxl);
    // mixerline info
    intRet := mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
    if intRet = MMSYSERR_NOERROR then begin
      FillChar(mxlc, SizeOf(mxlc),);
      mxlc.cbStruct := SizeOf(mxlc);
      mxlc.dwLineID := mxl.dwLineID;
      mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE;
      mxlc.cControls := ;
      mxlc.cbmxctrl := SizeOf(mxc);
      mxlc.pamxctrl := @mxc;
      // Get the mute control
      intRet := mixerGetLineControls(hMix, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
      if intRet = MMSYSERR_NOERROR then begin
        FillChar(mxcd, SizeOf(mxcd),);
        mxcd.cbStruct := SizeOf(TMIXERCONTROLDETAILS);
        mxcd.dwControlID := mxc.dwControlID;
        mxcd.cChannels := ;
        mxcd.cbDetails := SizeOf(MIXERCONTROLDETAILS_BOOLEAN);
        mxcd.paDetails := @mcdMute;
        if Value then
          mcdMute.fValue:=
        else
          mcdMute.fValue:=;
        // Get  mute
        intRet := mixerSetControlDetails(hMix, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
        if intRet <> MMSYSERR_NOERROR then
          ShowMessage('SetControlDetails Error');
      end else
       ShowMessage('GetLineInfo Error');
    end;
  end;
end;
end.
---------------------
作者:belllab
来源:CSDN
原文:https://blog.csdn.net/belllab/article/details/1554101
版权声明:本文为博主原创文章,转载请附上博文链接!

Delphi 内进行音量控制及静音的更多相关文章

  1. Android:Mstar Android8.0平台音量控制流程

    一.Speaker 音量.静音流程分析 java层音量设置首先调用到的是AudioManager.java中的方法,在这里有两种方法可以设置音量 setStreamVolume 和 adjustStr ...

  2. 【VC++技术杂谈001】音频技术之调节音量及设置静音

    本文主要介绍如何使用混音器Mixer API函数实现系统音量调节,以及设置静音. 1.混音器的作用及结构 1.1混音器的作用 声卡(音频卡)是计算机进行声音处理的适配器,具有三个基本功能: (1)音乐 ...

  3. Android之声音管理器《AudioManager》的使用以及音量控制

    以下为网上下载然后拼接-- Android声音管理AudioManager使用 手机都有声音模式,声音.静音还有震动,甚至震动加声音兼备,这些都是手机的基本功能.在Android手机中,我们同样可以通 ...

  4. PCM音量控制

    http://blog.jianchihu.net/pcm-volume-control.html 一.声音的相关概念 声音是介质振动在听觉系统中产生的反应.声音总可以被分解为不同频率不同强度正弦波的 ...

  5. Android原生音量控制【转】

    本文转载自:http://blog.csdn.net/u013082948/article/details/65630085 本文主要涉及AudioService.还是基于5.1.1版本的代码. Au ...

  6. WPF 媒体播放器(MediaElement)实例,实现进度和音量控制

    WPF 视频音频播放控件MediaElement实现进度控制,音量控制实例 说明: 1.Volume控制音量的大小,double类型,并且实现了属性依赖,可以用来双向绑定:在 0 和 1. 之间的线性 ...

  7. 【转】Delphi内嵌ASM简易教程

    Delphi内嵌ASM简易教程 作者:heiying2006-03-19 18:33分类:默认分类标签: 前言 Delphi作为一个快速高效的开发平台,使用的人越来越多,但熟悉在Delphi代码中嵌入 ...

  8. Android应用--简、美音乐播放器增加音量控制

    Android应用--简.美音乐播放器增加音量控制 2013年6月26日简.美音乐播放器继续完善中.. 题外话:上一篇博客是在6月11号发的,那篇博客似乎有点问题,可能是因为代码结构有点乱的原因,很难 ...

  9. krpano音量控制(我们已经转移到krpano中国网站 krpano360.com)

    需求: 实现音量控制,这是官网的样例, 本文已经转移 到 krpano中文网 p=148">http://krpano360.com/? p=148 很多其它教程关注微信公众号 krp ...

随机推荐

  1. IOS 将图片转换为圆角图

    UIImage+wiRoundedRectImage.h #import <UIKit/UIKit.h> @interface UIImage (wiRoundedRectImage) + ...

  2. Nowcoder 练习赛26E 树上路径 - 树剖

    Description 传送门 给出一个n个点的树,1号节点为根节点,每个点有一个权值 你需要支持以下操作 1.将以u为根的子树内节点(包括u)的权值加val 2.将(u, v)路径上的节点权值加va ...

  3. UI设计初学者必备的工具以及学习路线(附思维导图)

    今天千锋UI设计小编着重为大家介绍5个学习ui设计必须要会的工具和软件以及UI设计学习路线,希望能对大家所帮助. UI设计必要的工具和软件 1.PS 图像处理合成软件 ui设计核心软件,强大的图像处理 ...

  4. 【Selenium】通过xpath定位svg元素

    SVG 意为可缩放矢量图形(Scalable Vector Graphics)定位svg元素要用xpath的name()函数,比如//svg/line[2],要用//*[name()='svg']/* ...

  5. Python编程笔记(第二篇)二进制、字符编码、数据类型

    一.二进制 bin() 在python中可以用bin()内置函数获取一个十进制的数的二进制 计算机容量单位 8bit = 1 bytes 字节,最小的存储单位,1bytes缩写为1B 1KB = 10 ...

  6. 【统一异常处理】@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常

    1.利用springmvc注解对Controller层异常全局处理 对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service ...

  7. solr之创建core(搜索核心,包括索引和数据)的方法

    我的solrhome为D:\solrHome\solr step1:进入solrHome会看到collection1文件夹,创建该文件夹的副本,重命名为product 进入product文件夹,进入d ...

  8. python生成器初步了解

    一.生成器 生成器的本质就是迭代器    一个一个的创建对象   1.创建生成器的方式:    1.生成器函数 2.通过生成器表达式来获取生成器 3.类型转换 2.优点 节省内存 ,生成器本身就是代码 ...

  9. 796. Rotate String

    class Solution { public: bool rotateString(string A, string B) { if(A.length()==B.length()&& ...

  10. 对SVC和SVR的理解

    首先: support vector classify(SVC)支持分类机做二分类的,找出分类面,解决分类问题 support vector regression(SCR)支持回归机做曲线拟合.函数回 ...