如何检查我想播放的音频文件是否已播放? [英] How Do I Check If The Audio File I Want To Play Is Already Playing?

查看:125
本文介绍了如何检查我想播放的音频文件是否已播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿我正在开发一个程序,根据你在Kinect前面的动作触发音乐层。



但它不应该触发已经播放的声音。如何检查我想播放的声音文件是否已播放?



我正在使用C#





提前Thx:)

Hey I am developing a program that triggers music layers based on your movements in front of the Kinect.

But It should not trigger a sound that is already playing. How do I check if the sound-file I want to play is already playing?

I am using C#


Thx in advance :)

推荐答案

使用SoundPlayer类的唯一方法是使用 PlaySync [ ^ ]方法使用一个新的线程。当线程完成时,声音结束。



因此,在C#伪代码中,你会有这样的东西:



The only way to do this with the SoundPlayer class is to use the PlaySync[^] method using a new thread. When the thread completes, the sound is over.

So, in C# pseudo-code, you would have something like this:

public class SoundEffect
{
    string _soundFile;
    Thread _soundThread;
    bool _isStopped = true;

    public bool IsFinished { get { return _isStopped; } }    

    public SoundEffect(string soundFile)
    {
        _soundFile = soundFile;
    }

    public void Play()
    {
       if (!_isStopped)
           return;

       _soundThread = new Thread(PlayThread);
       _soundThread.Start();
    }

    private void PlayThread()
    {
        _isStopped = false;
        System.Media.SoundPlayer player = new System.Media.SoundPlayer(_soundFile);
        player.PlaySync();
        _isStopped = true;
    }
}





然后你可以看到声音是否完整。



Then you can see if the sound is complete or not.


这篇关于如何检查我想播放的音频文件是否已播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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