2017-09-11 4 views
-3
url = "http://r8---sn-03guxaxjvh-3c2r.googlevideo.com/videoplayback?sparams=dur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Csource%2Cexpire&mn=sn-03guxaxjvh-3c2r&ip=212.113.45.145&source=youtube&mm=31&mv=m&mime=video%2Fmp4&mt=1505092537&ipbits=0&initcwndbps=685000&dur=2223.728&id=o-AM9pUI9o5NsL8P-jGi5-w17xJOo-VVQ-TrWlMZaV17cp&key=yt6&lmt=1499875418101464&signature=4AACC08B22F2F1F343F5A044188CD751A6AD2F08.A7BA661DDC07639A7E414169226A35A700888AF3&ms=au&ei=HOS1WezYFZfq7gT40rnoAw&itag=22&pl=22&expire=1505114236&ratebypass=yes&title=Gothic+Rock+-+Dark+Music"; 


      streamPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
      try { 
       streamPlayer.setDataSource(url); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      try { 
       streamPlayer.prepare(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      streamPlayer.start();` 

私の質問は、デバイスにどのように私のstreamPlayerオブジェクトを格納するのですか?ちょっと!私はインターネットから受け取ったExternalStoragePublicファイルに保存したいと思いますが、私は本当に立ち往生しました。コードを教えてもらえますか?

答えて

0

試してみる

private static void downloadFile(String url, File outputFile) { 
    try { 
     URL u = new URL(url); 
     URLConnection conn = u.openConnection(); 
     int contentLength = conn.getContentLength(); 

     DataInputStream stream = new DataInputStream(u.openStream()); 

     byte[] buffer = new byte[contentLength]; 
     stream.readFully(buffer); 
     stream.close(); 

     DataOutputStream fos = new DataOutputStream(new       
     FileOutputStream(outputFile)); 
     fos.write(buffer); 
     fos.flush(); 
     fos.close(); 
    } catch(FileNotFoundException e) { 
    return; // swallow a 404 
    } catch (IOException e) { 
return; // swallow a 404 
    } 
} 
関連する問題