Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:58:56+00:00 2026-05-27T19:58:56+00:00

I am new in Android, i want to fetch the video file from web

  • 0

I am new in Android, i want to fetch the video file from web url and display the video but i am trying to download a file in my sd card and then play , but i got exception.

try
        {
            Runnable r = new Runnable() {
                public void run() {
                    try 
                    {
                        //mPlayer.setDataSource(item.getStrMusicUrl());
                        //////////////////////////
                        Log.i("Music Stream","Strats");
                        URL url = new URL(item.getStrMusicUrl());
                        URLConnection cn = url.openConnection();
                        cn.connect();
                        Log.i("Music Stream","Connected");
                        InputStream stream = cn.getInputStream();
                        if (stream != null)
                        {
                            Log.i("Music Stream","Getting the Stream");
                            File temp = File.createTempFile("replicaMedia", "dat");
                            String tempPath = temp.getAbsolutePath();
                            Log.i("Music File Path",tempPath);
                            FileOutputStream out = new FileOutputStream(temp);
                            Log.i("Music Stream","Stream saved");
                            byte buf[] = new byte[16384];
                            Log.i("Music Stream","reading the saved Stream");
                            int INTIAL_KB_BUFFER = 96*10/8;
                            int totalBytesRead = 0, incrementalBytesRead = 0;
                            do {
                                int numread = stream.read(buf);
                                if (numread <= 0)
                                    break;
                                out.write(buf, 0, numread);
                                Log.i("Stream Buffer"," "+numread);
                                totalBytesRead += numread;
                                incrementalBytesRead += numread;
                                totalKbRead = totalBytesRead/1000;
                                ////  Call MP to start 
                                if(totalKbRead >= INTIAL_KB_BUFFER)
                                {
                                    totalBytesRead = 0;
                                    if(mPlayer != null && mPlayer.isPlaying())
                                    {
                                        mPlayer.pause();
                                    }

                                    Log.i("Music Stream","Setting the stream path to MP");
                                    mPlayer.setDataSource(tempPath);    
                                    mPlayer.prepare();
                                    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                                    Log.i("Music Stream","Playing");
                                }

                            } while (true);

                            stream.close();                                

                        }
                        else
                        {
                            Log.i("Music Stream ","No Music Stream");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };

            new Thread(r).start();
        } catch (Exception e) {
            e.printStackTrace();
            if (mPlayer != null) 
            {
                mPlayer.stop();
                mPlayer.release();
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:58:57+00:00Added an answer on May 27, 2026 at 7:58 pm
     public class VedioViewActivity extends Activity {
     private ProgressDialog mProgress;
    private VideoView mVideoView;
    private String url;
    private String videoName;
    private boolean flag;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vedio_view_xml);
    
        flag=false;
        url=(String)getIntent().getExtras().getString("VideoUrl");
    
    
        mVideoView=(VideoView)findViewById(R.id.vedio_view);
        //File root = Environment.getExternalStorageDirectory();
    
        videoName=url.substring(url.lastIndexOf("/")+1);
    
        File file=new File("/mnt/sdcard/");
    
        File []fileArr=file.listFiles();
        int i;
        for(i=0;i<fileArr.length;i++){
            if(videoName.equals(fileArr[i].toString().substring(fileArr[i].toString().lastIndexOf("/")+1))){
                flag=true;
                break;
            }
        }
    
        if(flag){
            try{
                flag=false;
                URL u = new URL(url);
                HttpURLConnection c = (HttpURLConnection) u.openConnection();
                //Log.i("Main", "content "+c.getContentLength()+" "+fileArr[i].length());
                int fileSize=(int)fileArr[i].length();
                if(fileSize==c.getContentLength()){
                    mVideoView.setVideoPath("/mnt/sdcard/"+videoName);
                    mVideoView.setMediaController(new MediaController(this));
                    mVideoView.start();
                }else{
                    new NetCom().execute(url);
                }
                c.disconnect();
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }else {
            new NetCom().execute(url);
        }
    }
    
    class NetCom extends AsyncTask<String, String, String>{
    
        public NetCom() {
            mProgress=new ProgressDialog(VedioViewActivity.this);
            mProgress.setIcon(R.drawable.icon_72);
            mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgress.setMessage("Buffering Video...");
            mProgress.show();
        }
    
        @Override
        protected String doInBackground(String... param) {
    
            try{
    
                long availableByte=0;
                URL u = new URL(param[0]);
                HttpURLConnection c = (HttpURLConnection) u.openConnection();
                c.setRequestMethod("GET");
                c.setDoOutput(true);
                c.connect();
    
                File root = Environment.getExternalStorageDirectory();
                FileOutputStream f = new FileOutputStream(new File(root,videoName));
                InputStream in = c.getInputStream();
                availableByte=c.getContentLength();
    
                int bufferSize=(int)availableByte/100;
    
                byte[] buffer = new byte[1024];
                int len1 = 0;
                int total=0;
                int i=1;
                while ((len1 = in.read(buffer)) > 0 ) {
                    total+=len1;
                    if(total>=bufferSize){
                        total=0;
                        mProgress.setProgress(i++);
                    }
                    f.write(buffer,0, len1);
                }
                f.flush();
                f.close();
                in.close();
            }catch(Exception ex){
                ex.printStackTrace();
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            handler.handleMessage(null);
    
        }
        private Handler handler = new Handler() {
            public void handleMessage(android.os.Message msg) {
                try {
                    mProgress.dismiss();
    
                     String path = "/mnt/sdcard/"+videoName;
                     mVideoView.setVideoPath(path);
                     mVideoView.setMediaController(new MediaController(VedioViewActivity.this));
                     mVideoView.start();
    
                }catch(Exception ex){
    
                }
            }
    };
          }
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to the Android Platform and I want to fetch value's from
I am trying to save a file from the web to my Android device,
Hi guys I am new to android...I want to display a dynamic list of
I'm new in android and i'm trying to make an android app to display
Im a new Android programmer, and my question is this: I want to fetch
I'm a new student on Android. I'm able to fetch an xml from website
I want to fetch data from SQLITE database and display it in a LIST.
In Android I am using a service to fetch data from a web service
I am new in android .I want to make application of business card scanner
I Have been developing an Android RSS reader.I want to fetch the images from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.