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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:19:30+00:00 2026-05-20T07:19:30+00:00

Since I don’t have a flash player to play the video from Youtube itself,

  • 0

Since I don’t have a flash player to play the video from Youtube itself, I need to play it in my default MediaPlayer. The code I used is as follows:

MediaController mc = new MediaController(ctx);
        setContentView(R.layout.main);
        vv = (VideoView) findViewById(R.id.VideoView01);
        try {

            ur = Uri.parse(Url /*+ "&fmt=18"*/); // "&fmt=18"to convert to mp4
            System.out.println("Host = " + ur.getHost());
            System.out.println("Encoded Path = " + ur.getEncodedPath());

            vv.setVideoURI(ur);
            // vv.setVideoPath("http://www.daily3gp.com/vids/747.3gp");
            vv.setMediaController(mc);
            vv.requestFocus();
            vv.start();
            mc.show();

        } catch (Exception ex) {
            System.out.println("Exception!!!!!!!!!!!!!!!! "
                    + ex.getMessage());
        }

The thing is….It is getting the link and when we give the link to the player, it say’s This Video cannot be Played…..

Please help !!!!!!!!!!!!

  • 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-20T07:19:31+00:00Added an answer on May 20, 2026 at 7:19 am
    private static void play(String videoId, int format, String encoding,
            String userAgent, File outputdir, String extension)
            throws Throwable {
        log.fine("Retrieving " + videoId);
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("video_id", videoId));
        qparams.add(new BasicNameValuePair("fmt", "" + format));
        URI uri = getUri("get_video_info", qparams);
        System.out.println("************JavaYoutubeDownloade.play() Uri = "
                + uri.toString());
        System.out.println("JavaYoutubeDownloade.play() User Agent = "
                + userAgent);
        CookieStore cookieStore = new BasicCookieStore();
        HttpContext localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(uri);
        if (userAgent != null && userAgent.length() > 0) {
            httpget.setHeader("User-Agent", userAgent);
        }
    
        log.finer("Executing " + uri);
        HttpResponse response = httpclient.execute(httpget, localContext);
        HttpEntity entity = response.getEntity();
        if (entity != null && response.getStatusLine().getStatusCode() == 200) {
            InputStream instream = entity.getContent();
            String videoInfo = getStringFromInputStream(encoding, instream);
            if (videoInfo != null && videoInfo.length() > 0) {
                List<NameValuePair> infoMap = new ArrayList<NameValuePair>();
                URLEncodedUtils
                        .parse(infoMap, new Scanner(videoInfo), encoding);
                String downloadUrl = null;
                filename = videoId;
    
                for (NameValuePair pair : infoMap) {
                    String key = pair.getName();
                    String val = pair.getValue();
                    log.finest(key + "=" + val);
                    if (key.equals("title")) {
                        filename = val;
                    } else if (key.equals("fmt_url_map")) {
                        String[] formats = commaPattern.split(val);
                        boolean found = false;
                        for (String fmt : formats) {
                            String[] fmtPieces = pipePattern.split(fmt);
                            if (fmtPieces.length == 2) {
                                int pieceFormat = Integer
                                        .parseInt(fmtPieces[0]);
                                log.fine("Available format=" + pieceFormat);
                                if (pieceFormat == format) {
                                    // found what we want
                                    downloadUrl = fmtPieces[1];
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (!found) {
                            log.warning("Could not find video matching specified format, however some formats of the video do exist (use -verbose).");
                        }
                    }
                }
    
                filename = cleanFilename(filename);
                if (filename.length() == 0) {
                    filename = videoId;
                } else {
                    filename += "_" + videoId;
                }
                filename += "." + extension;
    
    
                File outputfile = new File(outputdir, filename);
                if (!outputfile.exists()) {
                    outputfile.createNewFile();
    
                }
                //downloadedFile = outputdir.getPath() + "/" + filename;
    
                if (downloadUrl != null) {
                    downloadWithHttpClient(userAgent, downloadUrl, outputfile);
    
                } else {
                    log.severe("Could not find video");
                }
            } else {
                log.severe("Did not receive content from youtube");
            }
        } else {
            log.severe("Could not contact youtube: " + response.getStatusLine());
        }
    }
    
    private static void downloadWithHttpClient(String userAgent,
            String downloadUrl, File outputfile) throws Throwable {
        HttpGet httpget2 = new HttpGet(downloadUrl);
        if (userAgent != null && userAgent.length() > 0) {
            httpget2.setHeader("User-Agent", userAgent);
        }
    
        log.finer("Executing " + httpget2.getURI());
        HttpClient httpclient2 = new DefaultHttpClient();
        HttpResponse response2 = httpclient2.execute(httpget2);
        HttpEntity entity2 = response2.getEntity();
        if (entity2 != null && response2.getStatusLine().getStatusCode() == 200) {
            double length = entity2.getContentLength();
            if (length <= 0) {
                // Unexpected, but do not divide by zero
                length = 1;
            }
            InputStream instream2 = entity2.getContent();
    
            System.out.println("Writing "
                    + commaFormatNoPrecision.format(length) + " bytes to "
                    + outputfile);
            if (outputfile.exists()) {
                outputfile.delete();
            }
    
            FileOutputStream outstream = new FileOutputStream(outputfile);
            try {
                byte[] buffer = new byte[BUFFER_SIZE];
                double total = 0;
                int count = -1;
                int progress = 10;
                long start = System.currentTimeMillis();
                while ((count = instream2.read(buffer)) != -1) {
                    total += count;
                    int p = (int) ((total / length) * ONE_HUNDRED);
                    if (p >= progress) {
                        long now = System.currentTimeMillis();
                        double s = (now - start) / 1000;
                        int kbpers = (int) ((total / KB) / s);
                        System.out.println(progress + "% (" + kbpers + "KB/s)");
                        progress += 10;
                    }
                    outstream.write(buffer, 0, count);
                }
                outstream.flush();
            } finally {
                outstream.close();
            }
            System.out.println("Done");
        }
    }
    

    Atfirst, the URL that I gave for download was incorrect. Now, it is working…

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

Sidebar

Related Questions

I have not tried anything since I don't know from where to start. How
Since I don't have a machine to test this I kindly need your help
I am creating a threadpool and since I don't need any output from my
I'm considering publishing my application to Play Store. And since I don't have yet
I don't know how php.ini was configured since I don't have access to it.
I'm reading this code sample : And since I don't know C#, I decided
This may be a little hard to describe since I don't have a sample.
This might be a simple one, but since I don't have much knowledge about
Since I have no errors I don't know if this is the right place
Since I don't really have a good idea for word to search with myself

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.