2017-03-06 18 views
2

自己証明済みのhttpsサーバ(私の場合はサブソニックミュージックサーバ)からのストリーミングに関するChromecastの制限を克服するために、Androidアプリの一部として既に実行されているNanoHTTPDサーバのインスタンスを利用しています。このアイデアは、Subsonicサーバー(SSL)からストリームを送信し、NanoHTTP.ResponseをChromecastに戻すためにそのストリームを新しいストリーム(SSL以外)に接続することです。どのように私は、HTTPS暗号化されたオーディオを変換するか、

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

だから、一言で言えば:私はのInputStreamが(MediaPlayerの通過果たしている)サブソニックサーバーから作業が、次の呼び出しのために暗号化されていないストリームを再する方法がわからない持っています暗号化されたオーディオストリームをオンザフライでストリームするか?NanoHTTPD - httpsストリームをhttpに変換する

答えて

0

[OK]を管理して、これをすべて有効にします。 httpsを使用する亜音速サーバー、Androidからアクセス可能、サーバーの自己署名証明書を使用してChromecast httpsがオンの場合、AndroidクライアントとChromecastの両方が、Androidクライアントで実行されているnanoohttpdプロキシサーバーを使用して、それぞれAndroid MediaPlayerとhtml5オーディオ要素にストリーミングします。 Android上で実行されている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

関連する問題