0

There is a problem with parsing a Url to a youtube video in my App.

Actually I should read video id from server then concatenate it with the ordinary link for youtube videos like this

the correct url is "https://www.youtube.com/watch?v=" + "Vuxmpogks64" the url after parsing when calling intent ONLY appear like http://www.youtube.com/watch?v= %EF%BB%BF Vuxmpogks64 and gives error video not found !

Why this part appear "%EF%BB%BF" ??

The code as follow

String myVideo = readAquaVideo();
        String[] ar = myVideo.split("[,]");
        video_id = ar[0];
        video_id = video_id.trim();


StringBuffer sb = new StringBuffer("");
        String url = "https://www.youtube.com/watch?v=";
        sb.append(url);
        sb.append(video_id);

        video_url = sb.toString().trim();



public static String readAquaVideo() {

        BufferedReader in = null;
        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI("http://epic-demo.com/dunes/video.php"));

            HttpResponse response = client.execute(request);

            BufferedReader ien = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");

            while ((line = ien.readLine()) != null) {
                sb.append(line + NL);
            }
            ien.close();
            video_id = sb.toString();
            video_id = video_id.trim();

            Log.d("parsing video",video_id);

        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {

                    e.printStackTrace();
                }
            }
        }
        return video_id;
        }


Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(video_url));
startActivity(intent); 
Shymaa Othman
  • 239
  • 1
  • 3
  • 16
  • i tried with this url="https://www.youtube.com/watch?v=" + "Vuxmpogks64"; and intent startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(url))); works fine on my device – Raghunandan May 25 '13 at 05:17
  • It works fine if it is hard coded , but the problem occurs when reading id from server and concatenate it to the ordinary "https://www.youtube.com/watch?v=" , I am sure to return id string correctly but when calling intent error appear in logcat telling that id is wrong and link appear like http://www.youtube.com/watch?v=%EF%BB%BFVuxmpogks64 – Shymaa Othman May 25 '13 at 06:18
  • then your appending is the problem. cross check it again – Raghunandan May 25 '13 at 06:20
  • I can print url after appending and it seems correct in logcat . Although when copying it to browser and press go it turns to this wrong form youtube.com/watch?v=%EF%BB%BFVuxmpogks64 , I cannot get what is the problem , please help ! – Shymaa Othman May 25 '13 at 21:08
  • why do you copy it a browser. Use the youtube app installed in your device and play. Check the answer in the link @ http://stackoverflow.com/questions/3286067/url-encoding-in-android. I guess you need to encode url to utf 8 – Raghunandan May 26 '13 at 03:34

0 Answers0