如何获得RTSP网址是什么? [英] How to get RTSP URL?
本文介绍了如何获得RTSP网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了包括视频查看应用程序,这是我的问题。
I am Developing an application which consists of video-view,Here is my problem
- 当我加载正常的网址无法访问,是YouTube的网址
- 如何转换上面的网址RTSP?
- 在我所使用的链接 http://www.youtube.com/watch?v= 8mIOkkkA2jA
code,我曾尝试:
Code which i have tried:
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView); Uri video = Uri.parse("youtube.com/watch?v=8mIOkkkA2jA";);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
请你们u能解释我如何实现这一目标? 在此先感谢!!!!!!
Please guys can u explain me how to achieve this? Thanks in advance!!!!!!
推荐答案
注:工作只Android手机(非片)
Note:Working only android mobile(Not in Tablet)
private class YourAsyncTask extends AsyncTask<Void, Void, Void>`enter code here`
{
ProgressDialog progressDialog;
@Override
protected void onPreExecute()
{
super.onPreExecute();
progressDialog = ProgressDialog.show(AlertDetail.this, "", "Loading Video wait...", true);
}
@Override
protected Void doInBackground(Void... params)
{
try
{
String url = "http://www.youtube.com/watch?v=1FJHYqE0RDg";
videoUrl = getUrlVideoRTSP(url);
Log.e("Video url for playing=========>>>>>", videoUrl);
}
catch (Exception e)
{
Log.e("Login Soap Calling in Exception", e.toString());
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
progressDialog.dismiss();
/*
videoView.setVideoURI(Uri.parse("rtsp://v4.cache1.c.youtube.com/CiILENy73wIaGQk4RDShYkdS1BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
videoView.setMediaController(new MediaController(AlertDetail.this));
videoView.requestFocus();
videoView.start();*/
videoView.setVideoURI(Uri.parse(videoUrl));
MediaController mc = new MediaController(AlertDetail.this);
videoView.setMediaController(mc);
videoView.requestFocus();
videoView.start();
mc.show();
}
}
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
{
String id = null;
try
{
String query = new URL(url).getQuery();
if (query != null)
{
String[] param = query.split("&");
for (String row : param)
{
String[] param1 = row.split("=");
if (param1[0].equals("v"))
{
id = param1[1];
}
}
}
else
{
if(url.contains("embed"))
{
id = url.substring(url.lastIndexOf("/") + 1);
}
}
}
catch(Exception ex)
{
Log.e("Exception", ex.toString());
}
return id;
}
这篇关于如何获得RTSP网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文