0
//此方法只顯示了YouTube上載Android的YouTube視頻與RSTP和vnd.youtube://打
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + videoId)) startActivity(intent);
//第二種方法是不是在所有 2播放視頻。
public class MyTask extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressBar.setVisibility(LinearLayout.VISIBLE);
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
url=getUrlVideoRTSP(urlRstp[0]);
rstlUrl=Uri.parse(url);
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
//Toast.makeText(VODVideoPlayActivity.this, url, Toast.LENGTH_LONG).show();
//System.out.println(url);
mVideoView.setVideoURI(rstlUrl);
//MediaController mc = new MediaController(VODVideoPlayActivity.this);
//mVideoView.setMediaController(mc);
//mVideoView.requestFocus();
mVideoView.start();
//mc.show();
mProgressBar.setVisibility(LinearLayout.GONE);
}
}
public static String getUrlVideoRTSP(String urlYoutube)
{
try
{
String gdy = "http://gdata.youtube.com/feeds/api/videos/";
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
String id = extractYoutubeId(urlYoutube);
URL url = new URL(gdy + id);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
Document doc = documentBuilder.parse(connection.getInputStream());
Element el = doc.getDocumentElement();
NodeList list = el.getElementsByTagName("media:content");///media:content
String cursor = urlYoutube;
for (int i = 0; i < list.getLength(); i++)
{
Node node = list.item(i);
if (node != null)
{
NamedNodeMap nodeMap = node.getAttributes();
HashMap<String, String> maps = new HashMap<String, String>();
for (int j = 0; j < nodeMap.getLength(); j++)
{
Attr att = (Attr) nodeMap.item(j);
maps.put(att.getName(), att.getValue());
}
if (maps.containsKey("yt:format"))
{
String f = maps.get("yt:format");
if (maps.containsKey("url"))
{
cursor = maps.get("url");
}
if (f.equals("1"))
return cursor;
}
}
}
return cursor;
}
catch (Exception ex)
{
Log.e("Get Url Video RTSP Exception======>>", ex.toString());
}
return urlYoutube;
}
protected static String extractYoutubeId(String url) throws MalformedURLException