mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-11-24 08:57:16 +08:00
播放器新增schema参数支持指定拉流协议
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include "MediaPlayer.h"
|
||||
#include "Common/config.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
@@ -36,7 +37,7 @@ static void setOnCreateSocket_l(const std::shared_ptr<PlayerBase> &delegate, con
|
||||
}
|
||||
|
||||
void MediaPlayer::play(const string &url) {
|
||||
_delegate = PlayerBase::createPlayer(_poller, url);
|
||||
_delegate = PlayerBase::createPlayer(_poller, url, (*this)[Client::kSchema]);
|
||||
assert(_delegate);
|
||||
setOnCreateSocket_l(_delegate, _on_create_socket);
|
||||
_delegate->setOnShutdown(_on_shutdown);
|
||||
|
||||
@@ -26,7 +26,7 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, const string &url_in) {
|
||||
PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, const string &url_in, const std::string &schema) {
|
||||
auto poller = in_poller ? in_poller : EventPollerPool::Instance().getPoller();
|
||||
std::weak_ptr<EventPoller> weak_poller = poller;
|
||||
auto release_func = [weak_poller](PlayerBase *ptr) {
|
||||
@@ -70,13 +70,13 @@ PlayerBase::Ptr PlayerBase::createPlayer(const EventPoller::Ptr &in_poller, cons
|
||||
return PlayerBase::Ptr(new RtmpPlayerImp(poller), release_func);
|
||||
}
|
||||
if ((strcasecmp("http", prefix.data()) == 0 || strcasecmp("https", prefix.data()) == 0)) {
|
||||
if (end_with(url, ".m3u8") || end_with(url_in, ".m3u8")) {
|
||||
if (end_with(url, ".m3u8") || end_with(url_in, ".m3u8") || schema == "hls") {
|
||||
return PlayerBase::Ptr(new HlsPlayerImp(poller), release_func);
|
||||
}
|
||||
if (end_with(url, ".ts") || end_with(url_in, ".ts")) {
|
||||
if (end_with(url, ".ts") || end_with(url_in, ".ts") || schema == "ts") {
|
||||
return PlayerBase::Ptr(new TsPlayerImp(poller), release_func);
|
||||
}
|
||||
if (end_with(url, ".flv") || end_with(url_in, ".flv")) {
|
||||
if (end_with(url, ".flv") || end_with(url_in, ".flv") || schema == "flv") {
|
||||
return PlayerBase::Ptr(new FlvPlayerImp(poller), release_func);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
using Ptr = std::shared_ptr<PlayerBase>;
|
||||
using Event = std::function<void(const toolkit::SockException &ex)>;
|
||||
|
||||
static Ptr createPlayer(const toolkit::EventPoller::Ptr &poller, const std::string &strUrl);
|
||||
static Ptr createPlayer(const toolkit::EventPoller::Ptr &poller, const std::string &strUrl, const std::string &schema = "");
|
||||
|
||||
PlayerBase();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user