0

我正在尝试在我的应用中播放视频。当文件存储在资产文件夹中时它正在播放视频,但当文件在服务器上时它不播放视频。

I want to play video from server

我的源代码是

 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");
                InputStream in = am.open("http://inveniya.net/jasmine/test2.mp4");
                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;
    }

感谢您提前提供任何建议

4

1 回答 1

1

UPDATE

我解决了这个问题URL url = new URL("http://inveniya.net/jasmine/test2.mp4"); InputStream in = url.openStream();

它工作正常并从服务器播放视频。

于 2013-04-28T10:44:03.913 回答