开发者

Synchronizing Java Visualizer Audio and Visual

开发者 https://www.devze.com 2023-02-02 04:37 出处:网络
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'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:

  1. Read in the .mp3 as a FileInputStream.
  2. a) Convert the FileInputStream into a Bitstream and run the Visualizer OR b) Pas开发者_如何学JAVAs 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号