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