• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1479
  • Last Modified:

Need a FIFO in Java

Hi!

I've a audio stream whichI get via udp....

When the stream arrives as packet in 400 bytes, I need a FIFO where I can put more into it in the same time as I can playback it... Anybody got  a solution for that???
0
mamruoc
Asked:
mamruoc
1 Solution
 
girionisCommented:
Use two threads. One to play the audio and the other to store it in an ArrayList or another collection object.
0
 
mmuruganandamCommented:
use one of the list implementation... putting more on the same or playback, you have to implement on your own.
There is no built in support of that in Java as I know
0
 
CEHJCommented:
List fifo = Collections.synchronizedList(new ArrayList());


...


public void play() {
      if (fifo.isEmpty() == false) {
            byte[] bytes = (byte[])fifo.remove(0);
            playAudio(bytes);
      }
}      

public void queueForPlayback(byte[] bytes) {
      fifo.add(bytes);
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
mamruocAuthor Commented:
Thanks again...

Maybe you should be the person how's doing this Java application.. :D
0
 
CEHJCommented:
8-)
0
 
mamruocAuthor Commented:
Hi!!

Hope you're still there...

Can your FIFO store binary data?

Seems like it don't play back that well... But if I send a file with content:

\x0A, it seems to store and playback well....

regards
0
 
CEHJCommented:
>>Can your FIFO store binary data?

Yes, as you can see, i assumed using a byte[]. Playback is another thing of course ...
0
 
mamruocAuthor Commented:
Well,,

I just dropped using ArrayList and used Vector, seems like Vetor is more efficient....

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now