如何在不挂我的应用程序的情况下播放声音 [英] how can i play sound without hanging my app

查看:67
本文介绍了如何在不挂我的应用程序的情况下播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题,我需要你帮助天才导游



i希望在我的应用程序中播放声音

a wav文件一个接一个使用playound api



但是idont知道我必须使用的扫管笏旗帜



使用的代码



i have a big issue and i need ur help genious guiders

i want to play sound in my application
a wav file after another using playsound api

but idont know wat flags i must use right

the code used

[DllImport("winmm.dll")]
        private static extern bool PlaySound(string filename, int module, int snd_flg);
        
<blockquote class="FQ">
        private const int SND_SYNC = 0x0000;
       private const int SND_ASYNC = 0x0001;
       private const int SND_NODEFAULT = 0x0002;
       private const int SND_MEMORY = 0x0004;// SND_LOOP
       private const int SND_LOOP = 0x0008;
       private const int SND_NOSTOP = 0x0010;
       private const int SND_PURGE = 0x40;
       private const int SND_APPLICATION = 0x80;
       private const int SND_NOWAIT = 0x00002000;
       private const int SND_ALIAS = 0x00010000;
       private const int SND_ALIAS_ID = 0x00110000;
       private const int SND_FILENAME = 0x00020000;



      <blockquote class="FQ"><div class="FQA">Quote:</div>PlaySound(Application.StartupPath + @"\wavs\patient_no.wav", 0, SND_SYNC );

               for (int i = 0; i < wav_arr.Length - 1; i++)
               {
                 PlaySound(Application.StartupPath + @"\wavs\" + wav_arr[i] + ".wav", 0, SND_SYNC);
              }
                PlaySound(Application.StartupPath + @"\wavs\go_to_lab.wav", 0, SND_SYNC | SND_NODEFAULT | SND_PURGE);

                //PlaySound(null, 0, SND_PURGE);
</blockquote>  


  </blockquote>






当我使用异步时
...程序没​​有停止>>像计时器一样,但它只返回最后一个声音

如果我使用同步程序停止直到声音完成



我该如何解决它



这是一个问题和标志

但不知道哪个会起作用完美不要挂我的应用程序



thanx很多




when i use async... the program doesn't stop >>like timers ,, but it returns only the last sound
and if i use sync the program stops till sound finished

how can i fix it

it's a problem wth flags
but dont know which will work just perfect an dont hang my app

thanx alot

推荐答案

我假设这是C#......



跳过非托管代码,只需使用 System.Media.SoundPlayer [ ^ ]它将在单独的线程中播放声音,而不会锁定您的应用程序。
I'm assuming that this is C#...

Skip the unmanaged code, just use System.Media.SoundPlayer[^] which will play the sound in a separate thread without "locking up" your application.


这篇关于如何在不挂我的应用程序的情况下播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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