Humayun Kabir
Humayun Kabir

Reputation: 611

video playing from asset folder but not playing from server in android

I am trying to play video in my app. It is playing video when file is stored in asset folder but not playing video when file is on server.

I want to play video from server

My source code is

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

Thank you advance for any advice

Upvotes: 0

Views: 276

Answers (1)

Humayun Kabir
Humayun Kabir

Reputation: 611

UPDATE

I solved the problem with URL url = new URL("http://inveniya.net/jasmine/test2.mp4"); InputStream in = url.openStream();

It is working properly and playing video from server.

Upvotes: 1

Related Questions