• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1484
  • 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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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