同步 Java Visualizer 音频和视频
我在用 Java 为 .mp3 文件创建可视化工具时遇到了问题。我的目标是创建一个与正在播放的 .mp3 文件同步运行的可视化效果。
我目前可以可视化 .mp3 或播放它,但不能同时两者。我正在使用的库可能会使这变得比必要的更加棘手。
我当前:
- 将 .mp3 作为 FileInputStream 读入。
- a) 将 FileInputStream 转换为比特流并运行 Visualizer 或 b) 将 FileInputStream 传递给库 Play 方法,在该方法中将其转换为 一个比特流,对其进行解码并播放。
我正在使用 JLayer 库来播放和解码 .mp3。
我的问题是:如何同步这两个操作,以便我可以同时运行它们并且它们对齐(因此我的可视化对应于不断变化的频率)。这意味着它们也同时完成。
I've run into a problem creating a visualizer for .mp3 files in Java. My goal is to create a visualization that runs in time with the .mp3 file being played.
I can currently visualize an .mp3 OR play it, but not both at the same time. I am using libraries which may make this trickier than necessary.
I currently:
- Read in the .mp3 as a FileInputStream.
- a) Convert the FileInputStream into a Bitstream and run the Visualizer OR
b) Pass the FileInputStream to a library Play method where it converts it into
a Bitstream, decodes it, and plays it.
I am using the JLayer library to play and decode the .mp3.
My question is: how do I synchronize the two actions so that I can run both at the same time AND they line up (so my visualizations correspond to the changing frequencies). This implies that they finish at the same time as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试在线程中设置每个部分,然后同步计时元素,以便它们同时启动。
I would try and set up each part in a thread and then synchronize the timing elements so they start at the same time.
我目前正在研究同样的事情,并且找到了解决方案。
问题:同步方法和属性不允许并行访问。
解决方案:一个线程组中的两个线程并在该线程组上进行同步。
或*:用于可运行对象的缓存线程池以及该缓存池上的同步。那么你的流阅读器是一个可运行的,你的可视化是第二个可运行的。
效果很好。
I am currently working on the same thing and I found the solution.
The problem: synchronized methods and attributes that doesn't allow paraell access.
The solution: Two threads in one thread group and synchronization over that thread group.
or* : Cached thread pool for runnables and synchronization over that cached pool. then your stream reader is one runnable and your visualisation is the second runnable.
Works just fine.