确定何时关闭Java中的声音播放线程 [英] Determine when to close a sound-playing thread in Java
问题描述
我在玩Java中的声音文件,并正在寻找一个简单的方法来确定何时声音文件播放完毕,所以我可以杀线程。有一个简单的方法来做到这一点?
I am playing of a sound-file in Java, and is looking for a simple way to determine when the sound-file has finished playing so I can kill the thread. Is there a simple way to accomplish this?
推荐答案
您播放声音同步或异步。
Comments
You play sound either synchronously or asynchronously.
在情况下,你玩它同步(阻塞调用线程),你知道什么时候结束的声音播放 - 你的code增益控制然后
In case you play it synchronously (blocking the calling thread), you know when the sound ends playing — your code gain control then.
如果你异步播放(允许创建一个不同的线程),辅助线程将完成打右后自行终止。
In case you play it asynchronously (allowing a different thread to be created), the helper thread will terminate itself right after finishing playing.
请内存泄漏和理由的问题下面分享您的看法。
Please share your observations on memory leaking and reasons underneath the question.
这篇关于确定何时关闭Java中的声音播放线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!