【问题标题】:How to get RTSP URL from HTTPS URL? [closed]如何从 HTTPS URL 获取 RTSP URL? [关闭]
【发布时间】:2014-01-30 07:52:21
【问题描述】:

如何将 HTTPS 转换为 RTSP URL。

谁能为我提供正确的代码示例解决方案?

这是我的代码:

  MediaController mc = new MediaController(MainActivity.this);
        mc.setAnchorView(videoView);
        Uri video = Uri.parse(newurl);
        videoView.setMediaController(mc);
        videoView.setVideoURI(video);

【问题讨论】:

  • 这样我就可以在android设备上的videoview中播放http视频了

标签: android https youtube rtsp


【解决方案1】:

尝试以下方法。

注意:确保在任何后台线程中使用getUrlVideoRTSP 方法。使用 AsyncTask 或 Thread 执行网络操作。

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

示例

new Thread(new Runnable() {
    @Override
    public void run() {
        String newurl = getUrlVideoRTSP("http://www.youtube.com/watch?v=9fBcrzA-hWY"));
    }
}).start();

编辑

示例 1

Youtube 网址 => http://www.youtube.com/watch?v=44fZqJOQ_go
RTSP URL => rtsp://r5---sn-a5m7zu7e.c.youtube.com/CiILENy73wIaGQkK_pCTqNmH4xMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

Youtube 网址 => http://www.youtube.com/watch?v=9fBcrzA-hWY
RTSP URL => rtsp://r3---sn-a5m7zu7k.c.youtube.com/CiILENy73wIaGQlmhT4wr1zw9RMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

【讨论】:

  • 我正在检查这个问题.. :)
  • 没有。我不……只是验证您的观察结果……
  • 顺便说一句..我没有收到任何类型的错误。你给出的“观察”我已经实施并获得了 URL 链接.. ;)
  • @AshyP,很高兴能帮助我的朋友……祝你有美好的一天……:)
  • @AshyP,一个问题。您是否在不使用 Thread 的情况下运行代码?
【解决方案2】:
Note:Working only android mobile(Not in Tablate)

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

同类型问题:

How to get RTSP URL?

play streaming in VideoView, convert url to rtsp

【讨论】:

    猜你喜欢
    • 2011-12-17
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2018-01-21
    相关资源
    最近更新 更多