从资产文件夹播放视频但不从Android服务器播放

时间:2013-04-28 05:27:08

标签: android video video-streaming

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

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;
    }

感谢您提前获取任何建议

1 个答案:

答案 0 :(得分:1)

UPDATE

我用URL url = new URL("http://inveniya.net/jasmine/test2.mp4"); InputStream in = url.openStream();

解决了这个问题

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