2011-07-03 2 views
0

아래의 1.1mbs 데이터 속도의 라디오 이더넷 링크를 사용하여 언덕 계곡에서 스튜디오에서 계곡의 라디오 방송국을 실행하고 싶습니다. (아래) 찾았 어.Android에서 java로 IP에서 소리를 재생하는 방법

하지만에 코드를 원하는 : 다른가받을 수 있도록 IPv4의 IP 주소를 포함하는 텍스트 파일 소리

  • 파일을 다시에서 참 또는 거짓을 읽어받을

    1. 로드 안드로이드에서 전송 느린 연결에서 데이터를 저장하십시오.

    누군가 도와 줄 수 있습니까?

    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 a capture device that will capture linear audio 
    // data at 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 we could not find the relevant capturedevice. 
    System.exit(-1); 
    } 
    
    // Create a processor for this capturedevice & exit if we 
    // cannot create it 
    Processor processor = null; 
    try { 
    processor = Manager.createProcessor(di.getLocator()); 
    } catch (IOException e) { 
    System.exit(-1); 
    } catch (NoProcessorException e) { 
    System.exit(-1); 
    } 
    
    // configure the 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 the tracks and try to program one of them to 
    // output gsm data. 
    
    for (int i = 0; i < 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 { 
    // we could not set this track to gsm, so disable it 
    track[i].setEnabled(false); 
    } 
    } 
    
    // At this point, we have determined where we can send out 
    // gsm data or not. 
    // realize the processor 
    if (encodingOk) { 
    processor.realize(); 
    while (processor.getState() != Processor.Realized){ 
    try { 
    Thread.sleep(100); 
    } catch (InterruptedException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 
    } 
    // get the output datasource of the processor and exit 
    // if we fail 
    DataSource ds = null; 
    
    try { 
    ds = processor.getDataOutput(); 
    } catch (NotRealizedError e) { 
    System.exit(-1); 
    } 
    
    // hand this datasource to manager for creating an RTP 
    // datasink our RTP datasink will multicast the 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); 
    } 
    } 
    } 
    } 
    

    수신기 : 그것은 로컬 네트워크를 통해이 멀티 캐스팅을 할 수 있도록 완벽하게 가능 소리

    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 for RTP"); 
    System.exit(-1); 
    } 
    
    // Create a player for this 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 for 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); 
    } 
    } 
    
    } 
    
  • +0

    서식이 모두 왜 우분투입니까? –

    +0

    이것은 흥미로운 프로젝트처럼 들리지만, 무엇이 도움이 필요합니까? – Tom

    +0

    정확히 수행해야하는 참/거짓 비트는 무엇입니까? – Tom

    답변

    0

    . AFAIK는 이 아니며은 인터넷을 통해 작동합니다. this도 참조하십시오. 멀티 캐스팅을위한 장치 지원은 분명히 매우 불안정합니다. 연구를 해보고 함께 작업하는 Android 기기가 실제로 소프트웨어 및 하드웨어 수준에서이를 지원하는지 확인하십시오. 경고 Emptor.