From c02438f9c85a9f5db83659f4bcddbc63231817e4 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 21 May 2020 14:10:27 +0800 Subject: [PATCH] =?UTF-8?q?hls=E6=92=AD=E6=94=BE=E5=99=A8=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=B8=A6=E5=8F=82=E6=95=B0=E7=9A=84url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Player/PlayerBase.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Player/PlayerBase.cpp b/src/Player/PlayerBase.cpp index 526c8ffc..ffe54f28 100644 --- a/src/Player/PlayerBase.cpp +++ b/src/Player/PlayerBase.cpp @@ -23,14 +23,20 @@ static bool end_of(const string &str, const string &substr){ return pos != string::npos && pos == str.size() - substr.size(); } -PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const string &strUrl) { +PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const string &url_in) { static auto releasePlayer = [](PlayerBase *ptr){ onceToken token(nullptr,[&](){ delete ptr; }); ptr->teardown(); }; - string prefix = FindField(strUrl.data(), NULL, "://"); + string url = url_in; + string prefix = FindField(url.data(), NULL, "://"); + auto pos = url.find('?'); + if (pos != string::npos) { + //去除?后面的字符串 + url = url.substr(0, pos); + } if (strcasecmp("rtsps",prefix.data()) == 0) { return PlayerBase::Ptr(new TcpClientWithSSL(poller),releasePlayer); @@ -48,7 +54,7 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &poller,const st return PlayerBase::Ptr(new RtmpPlayerImp(poller),releasePlayer); } - if ((strcasecmp("http",prefix.data()) == 0 || strcasecmp("https",prefix.data()) == 0) && end_of(strUrl, ".m3u8")) { + if ((strcasecmp("http",prefix.data()) == 0 || strcasecmp("https",prefix.data()) == 0) && end_of(url, ".m3u8")) { return PlayerBase::Ptr(new HlsPlayerImp(poller),releasePlayer); }