How to play sound from a IP in java with Android -


i want run radio station hill top studio in valley using radio ethernet link of 1.1 mbs data rate below example code (below) found.

but want code to:

  1. load text file containing ipv4 ip address receive sound
  2. read true or false file re transmit android receive save data on such slow connection.

can please?

import java.io.ioexception; import java.util.vector; import javax.media.capturedeviceinfo; import javax.media.capturedevicemanager; import javax.media.datasink; import javax.media.manager; import javax.media.medialocator; import javax.media.noplayerexception; import javax.media.noprocessorexception; import javax.media.notrealizederror; import javax.media.player; import javax.media.processor; import javax.media.control.formatcontrol; import javax.media.control.trackcontrol; import javax.media.format.audioformat; import javax.media.protocol.contentdescriptor; import javax.media.protocol.datasource;  public class simplevoicetransmiter {  /** * @param args */ public static void main(string[] args) { // first find capture device capture linear audio // data @ 8bit 8khz audioformat format= new audioformat(audioformat.linear, 8000, 8, 1); vector devices= capturedevicemanager.getdevicelist( format); capturedeviceinfo di= null;  if (devices.size() > 0) { di = (capturedeviceinfo) devices.elementat( 0); } else { // exit if not find relevant capturedevice. system.exit(-1); }  // create processor capturedevice & exit if // cannot create processor processor = null; try { processor = manager.createprocessor(di.getlocator()); } catch (ioexception e) { system.exit(-1); } catch (noprocessorexception e) { system.exit(-1); }  // configure processor  processor.configure();  while (processor.getstate() != processor.configured){ try { thread.sleep(100); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } }  processor.setcontentdescriptor( new contentdescriptor( contentdescriptor.raw));  trackcontrol track[] = processor.gettrackcontrols();  boolean encodingok = false;  // go through tracks , try program 1 of them // output gsm data.  (int = 0; < track.length; i++) { if (!encodingok && track[i] instanceof formatcontrol) {  if (((formatcontrol)track[i]). setformat( new audioformat(audioformat.gsm_rtp, 8000, 8, 1)) == null) {  track[i].setenabled(false); } else { encodingok = true; } } else { // not set track gsm, disable track[i].setenabled(false); } }  // @ point, have determined can send out // gsm data or not. // realize processor if (encodingok) { processor.realize(); while (processor.getstate() != processor.realized){ try { thread.sleep(100); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } } // output datasource of processor , exit // if fail datasource ds = null;  try { ds = processor.getdataoutput(); } catch (notrealizederror e) { system.exit(-1); }  // hand datasource manager creating rtp // datasink our rtp datasink multicast audio try { string url= "rtp://224.0.0.1:22224/audio/16";  medialocator m = new medialocator(url);  datasink d = manager.createdatasink(ds, m); d.open(); d.start(); processor.start(); } catch (exception e) { system.exit(-1); }  }  } } 

receiver:

import java.io.ioexception; import java.net.malformedurlexception; import javax.media.manager; import javax.media.medialocator; import javax.media.noplayerexception; import javax.media.player;  public class simplevoicereciver{  /** * @param args */ public static void main(string[] args) { string url= "rtp://192.168.1.111:22224/audio/16";  medialocator mrl= new medialocator(url);  if (mrl == null) { system.err.println("can't build mrl rtp"); system.exit(-1); }  // create player rtp session player player = null; try { player = manager.createplayer(mrl); } catch (noplayerexception e) { system.err.println("error:" + e); system.exit(-1); } catch (malformedurlexception e) { system.err.println("error:" + e); system.exit(-1); } catch (ioexception e) { system.err.println("error:" + e); system.exit(-1); }  if (player != null) { system.out.println("player created."); player.realize(); // wait realizing while (player.getstate() != player.realized){ try { thread.sleep(10); } catch (interruptedexception e) { e.printstacktrace(); } } player.start(); } else { system.err.println("player doesn't created."); system.exit(-1); } }  } 

it sounds possible multicasting on local network. afaik not work across internet. see this : device support multicasting apparently patchy. research, , make sure android devices work support on software , hardware level - many of them not. caveat emptor.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -