如何播放音乐文件的一个指定的时间量 [英] How to play a music file for a specified amount of time

查看:182
本文介绍了如何播放音乐文件的一个指定的时间量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的是打在指定的时间一个音乐文件,然后停止播放。然而,整个音乐文件正被播放。任何想法?

What I'm trying to do is play a music file for a specified duration, and then stop playing. However, the whole music file is being played. Any ideas?

我试着开始一个新的线程,仍然不起作用。

I've tried starting a new thread, still doesnt work.

推荐答案

问题是,PlaySync阻塞线程,因此其他消息将不会被处理。这包括从Tick事件你的止损指令。你必须使用常规的播放功能,这将是异步的,并创建一个新的线程来在播放文件。你必须处理所产生的多线程情况取决于如何应用程序的工作。

The problem is that PlaySync blocks the thread, so other messages won't be processed. This includes your stop command from the Tick event. You have to use the regular Play function, which will be asynchronous and creates a new thread to play the file in. You will have to handle the resulting multithreading situation depending on how your application works.

这篇关于如何播放音乐文件的一个指定的时间量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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