0

So ive got a need to play music files from a server on the network, in a java client app. I was thinking Sockets - have the server open a music file as a stream, and have the client connect to that and read & play it as an InputStream. Which would work - except AFAICS users wont be able to seek into the file(which they can currently for local Files), because I cant see how the Sockets stream can support that.

Any better ideas? Or a way to use the Sockets to seek?

JNI? I dont know enough about it to know if it would help.

The (totally lame) last resort is to use mapped network drives.

dalyons
  • 1,304
  • 3
  • 15
  • 23

2 Answers2

2

Before you implement your own protocol, it would be worthwhile to take a look at the Java Media Framework. It supports streaming audio, video, etc. Here is the Wikipedia entry if you want a description written by humans.

Dave Ray
  • 39,616
  • 7
  • 83
  • 82
  • Unfortunatly JMF is long dead. It doesnt support mp3s, except using a plugin, and even then it only plays about 1/3 of modern mp3s. Trust me, ive tried :). The only sane, semi-modern mp3 playing framework for java is Javazoom's jlayer & mp3spi. – dalyons Jan 22 '09 at 02:14
  • Yeah, I was afraid of that. Typical Sun. JavaFX might be another option, but it will also probably be abandoned soon :) – Dave Ray Jan 22 '09 at 17:12
0

You'll need to define some sort of protocol that allows random access. The simplest solution would probably be to use HTTP and its "Range" header, and request the data in short pieces.

"Real" streaming protocols such as RTSP are a lot more complex and usually use UDP instead of TCP.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720