MediaPlayer.cpp 2.12 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * MIT License
xzl committed
3
 *
xiongziliang committed
4
 * Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
xiongziliang committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
xzl committed
25 26
 */

xiongzilaing committed
27 28
#include <algorithm>
#include "MediaPlayer.h"
xzl committed
29 30
#include "Rtmp/RtmpPlayerImp.h"
#include "Rtsp/RtspPlayerImp.h"
xiongziliang committed
31
using namespace toolkit;
xzl committed
32

xiongziliang committed
33
namespace mediakit {
xzl committed
34

35 36 37 38 39
MediaPlayer::MediaPlayer(const EventPoller::Ptr &poller) {
    _poller = poller;
    if(!_poller){
        _poller = EventPollerPool::Instance().getPoller();
    }
xzl committed
40 41 42 43
}

MediaPlayer::~MediaPlayer() {
}
xiongziliang committed
44
void MediaPlayer::play(const string &strUrl) {
45
	_parser = PlayerBase::createPlayer(_poller,strUrl);
xiongziliang committed
46
	_parser->setOnShutdown(_shutdownCB);
47
	_parser->setOnPlayResult(_playResultCB);
48
    _parser->setOnResume(_resumeCB);
49
    _parser->setMediaSouce(_pMediaSrc);
50 51
	_parser->mINI::operator=(*this);
	_parser->play(strUrl);
xzl committed
52 53
}

54
EventPoller::Ptr MediaPlayer::getPoller(){
55
	return _poller;
xiongziliang committed
56
}
xiongziliang committed
57

xzl committed
58
void MediaPlayer::pause(bool bPause) {
59 60
	if (_parser) {
		_parser->pause(bPause);
xzl committed
61 62 63 64
	}
}

void MediaPlayer::teardown() {
65 66
	if (_parser) {
		_parser->teardown();
xzl committed
67 68 69 70
	}
}


xiongziliang committed
71
} /* namespace mediakit */