Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取RTSP URL?_Android - Fatal编程技术网

Android 如何获取RTSP URL?

Android 如何获取RTSP URL?,android,Android,我正在开发一个包含视频视图的应用程序,这是我的问题 当我加载了正常的url不工作时,Youtube的url 如何将上述URL转换为RTSP 我使用的链接 我尝试过的代码: VideoView videoView = (VideoView) findViewById(R.id.VideoView); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoVi

我正在开发一个包含视频视图的应用程序,这是我的问题

  • 当我加载了正常的url不工作时,Youtube的url
  • 如何将上述URL转换为RTSP
  • 我使用的链接
  • 我尝试过的代码:

    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();
    
    伙计们,你们能解释一下如何做到这一点吗?
    提前感谢

    我使用此代码让我的应用程序内YouTube视频正常工作:

    它所做的正是你想要的,因此,如果你不想要所有的代码,你可以从它检查YouTube视频流的位置撕下它,并在你的应用程序中使用它


    Tooks让我很难找到,希望能有所帮助

    我实际做的是:在这里编写代码

    if (responseCode == HttpURLConnection.HTTP_OK) { 
                          InputStream in = httpConnection.getInputStream(); 
    
                          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                          DocumentBuilder db = dbf.newDocumentBuilder();
    
                          Document dom = db.parse(in);      
                          Element docEle = dom.getDocumentElement();
    
                          NodeList nl = docEle.getElementsByTagName("entry");
                          if (nl != null && nl.getLength() > 0) {
                            for (int i = 0 ; i < nl.getLength(); i++) {
                              Element entry = (Element)nl.item(i);
                              Element title = (Element)entry.getElementsByTagName("title").item(0);
    
                              String titleStr = title.getFirstChild().getNodeValue();
    
                              Element content = (Element)entry.getElementsByTagName("content").item(0);
                              String contentStr = content.getAttribute("src");
    
                              Element rsp = (Element)entry.getElementsByTagName("media:content").item(1);
    
                              String anotherurl=rsp.getAttribute("url");
    
                             // System.out.println("content uri"+anotherurl);
    
                              Element photoUrl = (Element)entry.getElementsByTagName("media:thumbnail").item(0);
                              String photoStr = photoUrl.getAttribute("url");
    
    
                              JSONObject temp = new JSONObject();
                              try {
                                temp.put("Title", titleStr);
                                temp.put("Content", contentStr);
                                temp.put("PhotoUrl", photoStr);
                                temp.put("VideoUrl", anotherurl);
                              } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                              }
    
                              collection.put(temp);
    
                              //VideoCell cell = new VideoCell(titleStr);
                            }
                          }
                        }
    
    if(responseCode==HttpURLConnection.HTTP_OK){
    InputStream in=httpConnection.getInputStream();
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db=dbf.newDocumentBuilder();
    文档dom=db.parse(in);
    Element docEle=dom.getDocumentElement();
    NodeList nl=docEle.getElementsByTagName(“条目”);
    如果(nl!=null&&nl.getLength()>0){
    对于(int i=0;i
    这里名为
    另一个url
    的字符串是您要查找rtsp url的url


    希望能有所帮助。

    注意:仅适用于android mobile(不适用于平板电脑)

    私有类YourAsyncTask扩展了AsyncTask
    {
    进行对话进行对话;
    @凌驾
    受保护的void onPreExecute()
    {
    super.onPreExecute();
    progressDialog=progressDialog.show(AlertDetail.this,“,“加载视频等待…”,true);
    }
    @凌驾
    受保护的Void doInBackground(Void…参数)
    {
    尝试
    {
    字符串url=”http://www.youtube.com/watch?v=1FJHYqE0RDg";
    videoUrl=getUrlVideoRTSP(url);
    Log.e(“播放的视频url===>>>>”,视频url);
    }
    捕获(例外e)
    {
    e(“登录Soap调用异常”,e.toString());
    }
    返回null;
    }
    @凌驾
    受保护的void onPostExecute(void结果)
    {
    super.onPostExecute(结果);
    progressDialog.disclose();
    /*
    videoView.setVideoURI(Uri.parse(“rtsp://v4.cache1.c.youtube.com/CiILENy73wIaGQk4RDShYkdS1BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
    setMediaController(新的MediaController(AlertDetail.this));
    videoView.requestFocus();
    videoView.start();*/
    setVideoURI(Uri.parse(videoUrl));
    MediaController mc=新的MediaController(AlertDetail.this);
    videoView.setMediaController(mc);
    videoView.requestFocus();
    videoView.start();
    mc.show();
    }
    }
    公共静态字符串getUrlVideoRTSP(字符串urlYoutube)
    {
    尝试
    {
    字符串gdy=”http://gdata.youtube.com/feeds/api/videos/";
    DocumentBuilder DocumentBuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
    String id=extractYoutubeId(urlYoutube);
    URL=新URL(gdy+id);
    HttpURLConnection connection=(HttpURLConnection)url.openConnection();
    Document doc=documentBuilder.parse(connection.getInputStream());
    Element el=doc.getDocumentElement();
    NodeList list=el.getElementsByTagName(“媒体:内容”);///媒体:内容
    字符串游标=urlYoutube;
    对于(int i=0;iprivate class YourAsyncTask extends AsyncTask<Void, Void, Void>
        {
            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;
        }