How can I code a server/client video and audio streaming application?

后端 未结 3 1405
时光取名叫无心
时光取名叫无心 2020-12-13 16:32

I have to create a client/server system to stream video and audio. It would be very simple. Like youtube style. The server should attend clients providing a list of medias f

相关标签:
3条回答
  • 2020-12-13 16:55

    Check out the Java Media Framework (it has tutorials): http://java.sun.com/javase/technologies/desktop/media/jmf/

    Does this even work?

         while(true) {
            Runnable r = new ThreadedEchoHandler(incoming, i);
            Thread t = new Thread(r);
            t.start();
            i++;
         }
    

    I think your code would produce a bunch of threads with incoming socket connections... what you probably want to do is this:

         while(true) {
            Runnable r = new ThreadedEchoHandler(incoming.accept(), i);
            Thread t = new Thread(r);
            t.start();
            i++;
         }
    

    The ThreadedEchoHandler should take a Socket instead of a ServerSocket. Accept blocks until a client connects, otherwise you'll be spawning an infinite number of threads without a connection... I don't think you have anything that will stop you from doing that at the moment.

    0 讨论(0)
  • 2020-12-13 16:57

    Guys thank you very much for your answers and for editing title. I'm new here, new on java, new on networking. Why I'm making my skill on streaming? It's a study case. I'm looking at many tutorial about networking and I saw RTP but I didn't read about 'cause I thought (for reading on forums) it was just for real time streming meant as webcam streaming...but it's that I'm just so confused LOL

    Lirik of course what you said, I forgot some lines of coding

    while(true) {
       Socket incoming = s.accept();
       Runnable r = new ThreadedEchoHandler(incoming, i);
       ...
    

    or as you said

    while(true) {
      Runnable r = new ThreadedEchoHandler(s.accept(), i); 
      ...
    

    Taking a look at what you said guys. Kind regards!

    0 讨论(0)
  • 2020-12-13 17:07

    For streaming and talking to your clients, you need to define a protocol: Search the web for RTP and RTSP. It should give you a pretty good idea of what you need to implement these protocols or even create your own one.

    As for implementing, take a look at the red5 project: http://red5.org/

    Take a look at Xuggler as well: http://www.xuggle.com/xuggler/ This project will help you saving lots of lines of code. Note that its development has gone stale.

    Cheers.

    0 讨论(0)
提交回复
热议问题