MediaPlayer.cpp 1.06 KB
Newer Older
xzl committed
1 2 3 4 5 6 7
/*
 * MediaPlayer.cpp
 *
 *  Created on: 2016年12月5日
 *      Author: xzl
 */

xiongzilaing committed
8 9
#include <algorithm>
#include "MediaPlayer.h"
xzl committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include "Rtmp/RtmpPlayerImp.h"
#include "Rtsp/RtspPlayerImp.h"

using namespace ZL::Rtmp;
using namespace ZL::Rtsp;

namespace ZL {
namespace Player {

MediaPlayer::MediaPlayer() {
}

MediaPlayer::~MediaPlayer() {
	teardown();
}
xiongziliang committed
25
void MediaPlayer::play(const char* strUrl) {
xzl committed
26 27 28 29 30 31 32 33 34 35
	string strPrefix = FindField(strUrl, NULL, "://");
	if ((strcasecmp(m_strPrefix.data(),strPrefix.data()) != 0) || strPrefix.empty()) {
		//协议切换
		m_strPrefix = strPrefix;
		m_parser = PlayerBase::createPlayer(strUrl);
		m_parser->setOnShutdown(m_shutdownCB);
		m_parser->setOnVideoCB(m_onGetVideoCB);
		m_parser->setOnAudioCB(m_onGetAudioCB);
	}
	m_parser->setOnPlayResult(m_playResultCB);
xiongziliang committed
36 37
	m_parser->mINI::operator=(*this);
	m_parser->play(strUrl);
xzl committed
38 39
}

xiongziliang committed
40

xzl committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
void MediaPlayer::pause(bool bPause) {
	if (m_parser) {
		m_parser->pause(bPause);
	}
}

void MediaPlayer::teardown() {
	if (m_parser) {
		m_parser->teardown();
	}
}


} /* namespace Player */
} /* namespace ZL */