2017-02-28 20 views
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(); 

     } 
    } 
+0

你可以发布你的downloadFile方法吗? –

回答

0

我认为你必须动态传递链接如下图所示。

public interface RetrofitInterface { 

    @GET("/videos/{url}") 
    @Streaming 
    Call<ResponseBody> downloadFile(@Path("url") String url); 
} 

或调用您的界面,如下所示。

Call<ResponseBody> request = retrofitInterface.downloadFile(/*Your Video url*/);