Live Audio Streaming From One Android device to other on WIFI: Socket.receive() get Stuck -


i trying develop 1 app, live streams/broadcasts mic audio 1 android device another, here 1 device hotspot(the device streaming audio) , other devices connected hotspot listeners. took link streaming voice between android phones on wifi

when run app on listener device, application stuck on receive socket.receive(packet);

code sending audio (sender device)

   public void startstreaming(){      wifimanager wm = (wifimanager) getsystemservice(wifi_service);     final string ipaddress = formatter.formatipaddress(             wm.getconnectioninfo().getipaddress());      thread streamthread = new thread(new runnable() {          @override         public void run() {              try {                  int minbufsize = audiorecord.getminbuffersize(samplerate, channelconfig, audioformat);                 datagramsocket socket = new datagramsocket();                 log.d(msg, "socket created");                 byte[] buffer = new byte[minbufsize];                 log.d(msg,"buffer created of size " + minbufsize);                 datagrampacket packet;                 final inetaddress destination = inetaddress.getbyname(ipaddress);                  recorder = new audiorecord(mediarecorder.audiosource.mic,samplerate,channelconfig,audioformat,minbufsize);                  recorder.startrecording();                 while(status == true) {                     log.d(msg, "------recording--------");                      //putting buffer in packet                     packet = new datagrampacket (buffer,buffer.length,destination,port);                     socket.send(packet);                 }              }catch(unknownhostexception e) {                 log.e(msg, "unknownhostexception");             } catch (ioexception e) {                 log.e(msg, "ioexception");             }         }      });     streamthread.start(); } 

code receiving audio (listner device)

 public void startreceiving(){      wifimanager wm = (wifimanager) getsystemservice(wifi_service);     final string ipaddress = formatter.formatipaddress(             wm.getconnectioninfo().getipaddress());      thread receivethread = new thread (new runnable(){         public void run() {              try{                  if (checkpermission()){                      final inetaddress destination = inetaddress.getbyname(ipaddress);                     datagramsocket socket = new datagramsocket(50005,destination);                     byte[] buffer = new byte[256];                     int minbufsize = audiorecord.getminbuffersize(samplerate, channelconfig, audioformat);                      speaker = new audiotrack(audiomanager.stream_music,samplerate,channelconfig,audioformat,minbufsize,audiotrack.mode_stream);                      speaker.play();                     while(statusr == true) {                         try {                              datagrampacket packet = new datagrampacket(buffer,buffer.length);                              try                             {                              //after code execution stuck                                  socket.receive(packet);                                 log.d(msg, "$$$$$$$----------received-----------$$$$$$$$");                             }                             catch (java.net.sockettimeoutexception ex)                             {                                 // timeout                                 log.d(msg, "exception time out");                                 ex.printstacktrace();                             }                           //  socket.receive(packet);                              buffer=packet.getdata();                             //sending data audiotrack obj i.e. speaker                             speaker.write(buffer, 0, minbufsize);                             log.d(msg, "writing buffer content speaker");                          } catch(ioexception e) {                             log.e(msg,"ioexception");                             log.d(msg, "in exception");                             e.printstacktrace();                         }                         catch (exception e){                             log.d(msg, "e   ====in exception");                             e.printstacktrace();                         }                      }                  }else {                     log.d(msg, "------in request permission--------");                     requestpermission();                  }              } catch (socketexception e) {                 log.e("vr", "socketexception");                 e.printstacktrace();              }catch(unknownhostexception e) {                 log.e(msg, "unknownhostexception");             }         }     });     receivethread.start(); } 

what can understand client never found on particular socket here in case 50005,

how can resolve it? there other solution implement application scenario.

thanks in advance.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -