2013-04-28 71 views
0

我可以从资产文件夹播放视频,但我想从服务器上播放它。我如何更改我的应用程序?如何通过服务器URL替换资源文件夹视频播放

源代码是

class DownloadTask extends AsyncTask<String, Void, Object> { 
    protected Object doInBackground(String... args) { 
     AssetManager am = getAssets(); 
     String fileName = args[0]; 
     File file = new File(getExternalFilesDir(null), fileName); 
     Log.i("sushi", "Background thread starting"); 

     String state = Environment.getExternalStorageState(); 
     if (Environment.MEDIA_MOUNTED.equals(state)) { 
      try { 
       InputStream in = am.open("pages/rice/test2.3gp"); 
       FileOutputStream f = new FileOutputStream(file); 
       byte[] buffer = new byte[1024]; 
       int len1 = 0; 
       while ((len1 = in.read(buffer)) > 0) { 
        f.write(buffer, 0, len1); 
       } 
       f.close(); 
       in.close(); 
      } catch (Exception e) { 
       Log.d("sushi", e.getMessage()); 
      } 

      if (VideoActivity.this.pd != null) { 
       VideoActivity.this.pd.dismiss(); 
       VideoActivity.this.pd = null; 
      } 
     } 

     return null; 
    } 

以上代码从assets/pages/..夹播放视频很好。但我想从服务器获取视频文件并在我的应用中播放。

回答

相关问题