在我的应用程序中将 URL 解析为 youtube 视频时出现问题。
实际上,我应该从服务器读取视频 ID,然后将其与此类 youtube 视频的普通链接连接起来
正确的 url 是 " https://www.youtube.com/watch?v= " + "Vuxmpogks64" 调用意图时解析后的 url 仅显示为http://www.youtube.com/watch?v= %EF %BB%BF Vuxmpogks64 并给出错误视频未找到!
为什么这部分出现“%EF%BB%BF”??
代码如下
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);