0
正如你可以看到上面的網址下載視頻,我已經給了視頻的鏈接在靜態方式RetrofitInterface
類下載,如下圖所示:傳遞字符串使用改造
@GET("/videos/toystory.mp4")
但是,什麼如果我要通過視頻鏈接dynamically
,對於例如該字符串中包含的鏈接:
String strVidLink = ".....Vid Link.....";
使用改造的lib從URL下載的視頻,像這樣:
個RetrofitInterface.class:
public interface RetrofitInterface {
@GET("/videos/toystory.mp4")
@Streaming
Call<ResponseBody> downloadFile();
}
DownloadService.java:
private void initDownload(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://www.html5videoplayer.net")
.build();
RetrofitInterface retrofitInterface = retrofit.create(RetrofitInterface.class);
Call<ResponseBody> request = retrofitInterface.downloadFile();
try {
downloadFile(request.execute().body());
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
你可以發佈你的downloadFile方法嗎? –