2009-08-13 41 views

回答

2

我不認爲本地媒體播放器支持這一點。

1

您是否曾嘗試在URL中輸入用戶名和密碼?

http://<user>:<password>@<host>:<port>/<url-path> 
+0

是的,但它沒有奏效。謝謝 – 2009-08-13 12:58:39

3

這爲我工作:

public void setupMediaPlayer(){ 

    // Setup Media Player and Prepare to Play 
    media = new MediaPlayer(); 
    media.setAudioStreamType(AudioManager.STREAM_MUSIC); 

    // Authdata 
    String username = "username"; 
    String password = "password"; 

    // encrypt Authdata 
    byte[] toEncrypt = (username + ":" + password).getBytes(); 
    String encoded = Base64.encodeToString(toEncrypt, Base64.DEFAULT); 

    // create header 
    Map<String, String> headers = new HashMap<>(); 
    headers.put("Authorization","Basic "+encoded); 

    Uri uri = Uri.parse("http://your.full.url:port"); 

    try { 
     media.setDataSource(this,uri,headers); 
    } catch (IOException e) { 
     Log.e(TAG,"Exception "+e.getMessage()); 
    } 

    media.prepareAsync(); 

    media.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
     public void onPrepared(MediaPlayer mp) { 
      mp.start(); 
     } 
    }); 
}