zoukankan      html  css  js  c++  java
  • 播放一个wav文件

    use mmsystem;
    SndPlaySound('hello.wav',SND_FILENAME or SND_SYNC)

    ///////////////////////////////////
    unit PlaySnd1;

    interface

    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;

    type
      TForm1 = class(TForm)
        PlaySndFromFile: TButton;
        PlaySndFromMemory: TButton;
        PlaySndbyLoadRes: TButton;
        PlaySndFromRes: TButton;
        procedure PlaySndFromFileClick(Sender: TObject);
        procedure PlaySndFromMemoryClick(Sender: TObject);
        procedure PlaySndFromResClick(Sender: TObject);
        procedure PlaySndbyLoadResClick(Sender: TObject);
      private

        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.DFM}

    {$R snddata.res}

    uses MMSystem;

    procedure TForm1.PlaySndFromFileClick(Sender: TObject);
    begin
      sndPlaySound('hello.wav',
                    SND_FILENAME or SND_SYNC);
    end;

    procedure TForm1.PlaySndFromMemoryClick(Sender: TObject);
    var
      f: file;
      p: pointer;
      fs: integer;
    begin
      AssignFile(f, 'hello.wav');
      Reset(f,1);

      fs := FileSize(f);
      GetMem(p, fs);
      BlockRead(f, p^, fs);
      CloseFile(f);
      sndPlaySound(p,
                   SND_MEMORY or SND_SYNC);
      FreeMem(p, fs);
    end;

    procedure TForm1.PlaySndFromResClick(Sender: TObject);
    begin
      PlaySound('HELLO',
                hInstance,
                SND_RESOURCE or SND_SYNC);
    end;

    procedure TForm1.PlaySndbyLoadResClick(Sender: TObject);
    var
      h: THandle;
      p: pointer;
    begin
      h := FindResource(hInstance,
                        'HELLO',

                        'WAVE');
      h := LoadResource(hInstance, h);
      p := LockResource(h);
      sndPlaySound(p,
                   SND_MEMORY or SND_SYNC);
      UnLockResource(h);
      FreeResource(h);
    end;


    end.

  • 相关阅读:
    几种开源SIP协议栈对比OPAL,VOCAL,sipX,ReSIProcate,oSIP
    google开源的C++性能分析工具
    常用SNS开源系统比较
    推荐20个开源项目托管网站
    web2.0的几个开源项目
    开源src镜像
    Niagara解决设备连接应用的软件框架平台技术。
    Signing key has not been configured
    Mybatis 简单的CRUD 基于XML文件配置
    HDU4451Dressing(计数)
  • 原文地址:https://www.cnblogs.com/yzryc/p/6374447.html
Copyright © 2011-2022 走看看