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 8944421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:01:02+00:00 2026-06-15T12:01:02+00:00

I am trying to play a remote video file through intent(default media player) but

  • 0

I am trying to play a remote video file through intent(default media player) but I also want to save it locally while it is being streamed. I am trying following code to save the steam locally in a video file which is working fine. Now I want to start my intent as soon as the file is being streamed but when intent is started I get the error “Sorry this video can not be played“. Note that if I move the intent code to end of this method when streaming is complete( when downloadedSize==totalSize) then it works fine but I want to play while being streamed at the same time. Any help?

public String DownloadVideo(String Url, String fileName)
    {
    String filepath=null;
    try {
    URL url = new URL(Url);
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestMethod("GET");
    urlConnection.setDoOutput(true);
    urlConnection.connect();

    File SDCardRoot = Environment.getExternalStorageDirectory();
    File file = new File(SDCardRoot,fileName);
    if(file.createNewFile())
    {
    file.createNewFile();
    }
    FileOutputStream fileOutput = new FileOutputStream(file);
    InputStream inputStream = urlConnection.getInputStream();
    int totalSize = urlConnection.getContentLength();
    int downloadedSize = 0;

    byte[] buffer = new byte[1024];
    int bufferLength = 0; //used to store a temporary size of the buffer
    int counter=0;

    while ( (bufferLength = inputStream.read(buffer)) > 0 ) {

    fileOutput.write(buffer, 0, bufferLength);

    if(downloadedSize>2048)
    {
        Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.parse(file.getPath()),"video/*");
        startActivity(i);
    }
    downloadedSize += bufferLength;
    counter++;
    }
    fileOutput.close();
    if(downloadedSize==totalSize) {
        filepath=file.getPath();
                                }
    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    filepath=null;
    e.printStackTrace();
    }
    return filepath;

    }
  • 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-06-15T12:01:04+00:00Added an answer on June 15, 2026 at 12:01 pm

    I think the problem is in this line:

    i.setDataAndType(Uri.parse(file.getPath()),"video/*");
    

    Your passing the your local file to the Intent, but that is the one that has not been downloaded yet. I think you should use the Url to stream the video, and store the contents in file

    // Use the url of the remote location
    i.setDataAndType(Uri.parse(Url),"video/*");
    // Also, try to use lowercase for variables e.g. url vs Url
    

    That way, you are streaming the remote url, and saving the contents to your local file.
    I may be misinterpreting the code, but I would start by looking into that

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play a video file using JMF but it gives me
I'm trying to play a youtube video on my Android app, but I can't
I'm trying to play around with EJB remote call but I'm getting an error.
Im trying to build Win8 metro style application. Im trying to play remote video
I'm trying to play a remote MP3 file in my Xcode project, however the
I'm trying to play a video in a VideoView and I'm failing miserably. I'm
I am trying to play a sound in my javascript file document.getElementById(sound).innerHTML = <embed
So I'm trying to play a video and the following code has worked for
I am trying to create a video thumbnail for a file : 1- the
I am trying to connect a remote akka system to a play framework and

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.