2017-03-06 23 views
2

자체 인증 https 서버 (내 경우에는 Subsonic 음악 서버)에서 스트리밍하는 Chromecast의 제한을 극복하기 위해 Android 앱의 일부로 이미 실행중인 NanoHTTPD 서버의 인스턴스를 활용합니다. 아이디어는 Subsonic 서버 (SSL)에서 스트리밍하고 Chromecast로 NanoHTTP.Response의 새 스트림 (비 SSL)에 해당 스트림을 연결하는 것입니다. (MediaPlayer를 통해 재생) Subsonic 서버에서 작동하지만 다음 호출에 대해 암호화되지 않은 스트림을 다시 보내는 방법을 모르는 경우 InputStream이 있습니다.

new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "audio/mpeg", newStream);

요약하면 https로 암호화 된 오디오 즉석에서 해독 된 오디오 스트림으로 스트리밍합니까?NanoHTTPD - https 스트림을 http로 변환

답변

0

좋아,이 모든 작업을 관리 할 수 ​​있습니다. https를 사용하는 서브 소닉 서버 (Android에서 액세스 가능) 및 서버의 자체 서명 된 인증서를 사용하는 Chromecast https가 켜져 있으면 Android 및 Chromecast 모두 Android 클라이언트에서 실행되는 nanohttpd 프록시 서버를 사용하여 Android MediaPlayer 및 html5 오디오 요소로 각각 스트리밍합니다. 안드로이드에서 실행되는 nanohttpd 서버의 역할 기능을 재정의 다음 코드를 포함 : -

int filesize = .... obtained from Subsonic server for the track to be played 

// establish the https connection using the self-signed certificate 
// placed in the Android assets folder (code not shown here) 
HttpURLConnection con = _getConnection(subsonic_url,"subsonic.cer") 

// Establish the InputStream from the Subsonic server and 
// the Piped Streams for re-serving the unencrypted data 
// back to the requestor 
final InputStream is = con.getInputStream(); 
PipedInputStream sink = new PipedInputStream(); 
final PipedOutputStream source = new PipedOutputStream(sink); 

// On a separate thread, read from Subsonic and write to the pipe 
Thread t = new Thread(new Runnable() { 
       public void run() { 
        try { 
         byte[] b = new byte[1024]; 
         int len; 
         while ((len = is.read(b,0,1024)) != -1) 
          source.write(b, 0, len); 
         source.flush(); 
        } 
        catch (IOException e) { 
        } 
       }}); 

t.start(); 
sleep(200); // just to let the PipedOutputStream start up 

// Return the PipedInputStream to the requestor. 
// Important to have the filesize argument 
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, 
           "audio/mpeg", sink, filesize); 

난에 MP3 트랜스 코딩과 FLAC 파일을 스트리밍 나에게 FLAC 파일 크기지만 물론 MP3 스트림을 준 것으로 나타났다. 이것은 html5 오디오 요소를 처리하기가 어려웠으므로 스트림에 대한 Subsonic API 호출에 & 형식 = raw를 추가하는 것으로 되돌 렸습니다. 따라서 https를 통한 사용자의 구성에 상관없이 원시 형식의 스트림을 제공하며 테스트에서 지금까지 모두 잘 작동하는 것 같습니다.

+0

Ben Baron이 지적한 바에 따르면 ... https://groups.google.com/forum/#!topic/subsonic-app-developers/xpB14ZgZ75I 스트림 호출시 'estimateContentLength = true'를 사용할 수 있습니다. 원시 형식을 사용하지 않으려면 콘텐츠 헤더의 크기를 트랜스 코딩해야합니다. – milleph