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方法吗? –