MediaPlayer.cpp 1.36 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3 4 5
 *
 * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
 *
xiongziliang committed
6 7 8
 * 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.
xzl committed
9 10
 */

xiongzilaing committed
11 12
#include <algorithm>
#include "MediaPlayer.h"
xzl committed
13 14
#include "Rtmp/RtmpPlayerImp.h"
#include "Rtsp/RtspPlayerImp.h"
xiongziliang committed
15
using namespace toolkit;
xzl committed
16

xiongziliang committed
17
namespace mediakit {
xzl committed
18

19 20 21 22 23
MediaPlayer::MediaPlayer(const EventPoller::Ptr &poller) {
    _poller = poller;
    if(!_poller){
        _poller = EventPollerPool::Instance().getPoller();
    }
xzl committed
24 25 26 27
}

MediaPlayer::~MediaPlayer() {
}
xiongziliang committed
28
void MediaPlayer::play(const string &strUrl) {
29 30 31
    _delegate = PlayerBase::createPlayer(_poller,strUrl);
    _delegate->setOnShutdown(_shutdownCB);
    _delegate->setOnPlayResult(_playResultCB);
xiongziliang committed
32 33
    _delegate->setOnResume(_resumeCB);
    _delegate->setMediaSouce(_pMediaSrc);
34 35
    _delegate->mINI::operator=(*this);
    _delegate->play(strUrl);
xzl committed
36 37
}

38
EventPoller::Ptr MediaPlayer::getPoller(){
39
    return _poller;
xiongziliang committed
40
}
xiongziliang committed
41

xzl committed
42
void MediaPlayer::pause(bool bPause) {
43 44 45
    if (_delegate) {
        _delegate->pause(bPause);
    }
xzl committed
46 47 48
}

void MediaPlayer::teardown() {
49 50 51
    if (_delegate) {
        _delegate->teardown();
    }
xzl committed
52 53 54
}


xiongziliang committed
55
} /* namespace mediakit */