如何在Delphi中同时播放多个.wav文件 [英] How to play multiple .wav files simultaneously in delphi

查看:305
本文介绍了如何在Delphi中同时播放多个.wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要多.wav文件在Delphi中同时进行。

I wish to multiple .wav files simultaneously in delphi.

当我打开和开发平台的第一件事都是精品。
然而,当它试图打开第二个导致错误。

When I open and plat the first things are fine. However the second one causes a error when it tries to open.

这样看来,我只能同时使用一个媒体播放器....有没有解决这个办法我该怎么办?

It would appear that i can only use one media player at a time.... is there any way around this what do i do?

推荐答案

你会如何打单声音?当我想要很好的控制,我使用 waveout的的功能,如<一个href=\"http://stackoverflow.com/questions/3456748/what-is-the-simpliest-way-to-play-sound-from-array-data-in-delphi/3462724#3462724\">this回答。我的回答也有让你打使用线程的声音(即除其他事项外,asynchronically)。我的认为的,你可以在同一时间播放两个声音,通过简单地在同一时间启动两个这样的主题,如果你只更换全球 VAR s的全球 threadvar 秒。

How would you play a single sound? When I want fine control, I use the waveOut functions, as in this answer. My answer there also allows you to play the sound using a thread (that is, among other things, asynchronically). I think that you can play two sounds at the same time, by simply starting two such threads at the same time, if you only replace global vars with global threadvars.

打单声音最简单的方法是使用 PlaySound 。这可以asynchronically使用,但既然你问这个问题,我认为这不会让你两次使用此功能在一排开始的两个文件同时播放。但是:如果你创建一个线程,只有播放的声音(的共时的,以使播放finnished之前的线程没有死),那么你可以的可能的使用两个这样的线程同时播放两个音频文件。 (我有一个Delphi编译器没有访问权限了,所以恐怕我无法测试我的假​​设。)

The simplest way to play a single sound is to use PlaySound. This can be used asynchronically, but since you ask this question, I assume that this does not allow you to use this function twice in a row to start simultaneous playback of two files. But: If you create a thread that only plays the sound (synchronically so that the thread doesn't die before the playback is finnished), then you can probably use two such threads to play two audio files simultaneously. (I have no access to a Delphi compiler right now, so I am afraid that I cannot test my hypotheses.)

我的假设是,你可以使用两次调用 PlaySound 如果只有这个函数是被称为的两个不同的线程的,但显然这不是够好了。你真的需要两个不同的过程,现在看来,这是不好的(不言自明)。我试过

My hypothesis was that you could use two calls to PlaySound if only the function was called from two different threads, but apparently that is not good enough. You really need two different processes, it seems, which is bad (to state the obvious). I tried

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TSoundPlayerThread.Create(true) do
  begin
    SetFileName('C:\Users\Andreas Rejbrand\Downloads\Anna.wav');
    FreeOnTerminate := true;
    Resume;
  end;

  with TSoundPlayerThread.Create(true) do
  begin
    SetFileName('C:\Users\Andreas Rejbrand\Downloads\Mike.wav');
    FreeOnTerminate := true;
    Resume;
  end;
end;

unit SoundPlayerThread;

interface

uses
  Classes, MMSystem, Windows;

type
  TSoundPlayerThread = class(TThread)
  private
    { Private declarations }
    FAudioFileName: string;
  protected
    procedure Execute; override;
  public
    procedure SetFileName(const FileName: string);
  end;

implementation

procedure TSoundPlayerThread.Execute;
begin
  PlaySound(PChar(FAudioFileName), 0, SND_SYNC);
end;

procedure TSoundPlayerThread.SetFileName(const FileName: string);
begin
  FAudioFileName := FileName;
end;

end.

和只有后者波形文件播放。

and only the latter wave file was played.

其实我已经写了一个小的WAV文件库。用这种方法,我可以装载两个WAV文件,的合并的他们,并将结果发送到音频驱动程序。然而,太多code在这里发表。如果我离开的时间有一天我可能会写一个更轻量级的 PlaySimultaneously 程序和张贴。

I have actually written a small WAV file library. Using this, I can load two WAV files, merge them, and send the result to the audio driver. However, it is too much code to post here. If I get time left some day I might write a more lightweight PlaySimultaneously procedure and post it.

否则:的DirectX

Otherwise: DirectX?

这篇关于如何在Delphi中同时播放多个.wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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