mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-01 00:57:28 +08:00
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
*
|
|
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
|
*
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include <algorithm>
|
|
#include "MediaPlayer.h"
|
|
#include "Rtmp/RtmpPlayerImp.h"
|
|
#include "Rtsp/RtspPlayerImp.h"
|
|
using namespace toolkit;
|
|
|
|
namespace mediakit {
|
|
|
|
MediaPlayer::MediaPlayer(const EventPoller::Ptr &poller) {
|
|
_poller = poller ? poller : EventPollerPool::Instance().getPoller();
|
|
}
|
|
|
|
MediaPlayer::~MediaPlayer() {
|
|
}
|
|
|
|
static void setOnCreateSocket_l(const std::shared_ptr<PlayerBase> &delegate, const Socket::onCreateSocket &cb){
|
|
auto helper = dynamic_pointer_cast<SocketHelper>(delegate);
|
|
if (helper) {
|
|
helper->setOnCreateSocket(cb);
|
|
}
|
|
}
|
|
|
|
void MediaPlayer::play(const string &url) {
|
|
_delegate = PlayerBase::createPlayer(_poller, url);
|
|
assert(_delegate);
|
|
setOnCreateSocket_l(_delegate, _on_create_socket);
|
|
_delegate->setOnShutdown(_shutdownCB);
|
|
_delegate->setOnPlayResult(_playResultCB);
|
|
_delegate->setOnResume(_resumeCB);
|
|
_delegate->setMediaSouce(_pMediaSrc);
|
|
_delegate->mINI::operator=(*this);
|
|
_delegate->play(url);
|
|
}
|
|
|
|
EventPoller::Ptr MediaPlayer::getPoller(){
|
|
return _poller;
|
|
}
|
|
|
|
void MediaPlayer::setOnCreateSocket(Socket::onCreateSocket cb){
|
|
setOnCreateSocket_l(_delegate, cb);
|
|
_on_create_socket = std::move(cb);
|
|
}
|
|
|
|
void MediaPlayer::pause(bool pause) {
|
|
if (_delegate) {
|
|
_delegate->pause(pause);
|
|
}
|
|
}
|
|
|
|
void MediaPlayer::teardown() {
|
|
if (_delegate) {
|
|
_delegate->teardown();
|
|
}
|
|
}
|
|
|
|
|
|
} /* namespace mediakit */
|