Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reading a stream twice but download it only once

 
olze oli
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

following problem:
i have an audio player which retrieves a stream from a website and plays it, which works pretty good.
i want the user to be able to play forward. But i dont want the user to be able to play too far forward, so i have to detect how many bytes has been transfered. And thats where i get stuck, because i have a "wrapped" player class which plays the song from an EofSensorInputStream (thats an InputStream from apache which i cannot change to another InputStream) and i have the SliderUI which also uses the stream (passed as constructor argument) which should now detect how many bytes has been transfered.

I can read the the stream only once, so either in my SliderUI, but then the data is lost for the player. Or i play the song, but then the data is lost for the SliderUI.

Does anyone have an idea how to do this?
 
Andrey Kozhanov
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite get your problem.

As far as google says, EofSensorInputStream class is not final, so you can easily create its descendants and implement there any check you want.

And if you still want to read one stream several times, one of the possible solutions is to read data once in a 'buffer', and then read this buffer as many times as you want, like this:

Of course if your initial stream is too large or you need to read it simultaneously, this solution will not do.
 
olze oli
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using htmlunit and i think it would be overkill to create a new class and change the whole htmlunit code.
i think i got a solution or workaround:
download the stream as tmp file, play the song from it and get the filesize and compare it with the content length given by the http server
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!