mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
添加播放恢复事件
This commit is contained in:
parent
3e0e0ce2aa
commit
6a64917427
@ -45,6 +45,7 @@ void MediaPlayer::play(const string &strUrl) {
|
||||
_parser = PlayerBase::createPlayer(_poller,strUrl);
|
||||
_parser->setOnShutdown(_shutdownCB);
|
||||
_parser->setOnPlayResult(_playResultCB);
|
||||
_parser->setOnResume(_resumeCB);
|
||||
_parser->setMediaSouce(_pMediaSrc);
|
||||
_parser->mINI::operator=(*this);
|
||||
_parser->play(strUrl);
|
||||
|
@ -120,6 +120,12 @@ public:
|
||||
*/
|
||||
virtual void setOnPlayResult( const function<void(const SockException &ex)> &cb) {}
|
||||
|
||||
/**
|
||||
* 设置播放恢复回调
|
||||
* @param cb
|
||||
*/
|
||||
virtual void setOnResume( const function<void()> &cb) {}
|
||||
|
||||
/**
|
||||
* 获取播放进度,取值 0.0 ~ 1.0
|
||||
* @return
|
||||
@ -147,6 +153,10 @@ public:
|
||||
protected:
|
||||
virtual void onShutdown(const SockException &ex) {}
|
||||
virtual void onPlayResult(const SockException &ex) {}
|
||||
/**
|
||||
* 暂停后恢复播放时间
|
||||
*/
|
||||
virtual void onResume(){};
|
||||
};
|
||||
|
||||
template<typename Parent,typename Parser>
|
||||
@ -172,6 +182,13 @@ public:
|
||||
_playResultCB = cb;
|
||||
}
|
||||
|
||||
void setOnResume(const function<void()> &cb) override {
|
||||
if (_parser) {
|
||||
_parser->setOnResume(cb);
|
||||
}
|
||||
_resumeCB = cb;
|
||||
}
|
||||
|
||||
bool isInited(int analysisMs) override{
|
||||
if (_parser) {
|
||||
return _parser->isInited(analysisMs);
|
||||
@ -237,7 +254,14 @@ protected:
|
||||
}
|
||||
//播放成功却未初始化完毕,这个时候不回调汇报播放成功
|
||||
}
|
||||
void checkInited(int analysisMs){
|
||||
|
||||
void onResume() override{
|
||||
if(_resumeCB){
|
||||
_resumeCB();
|
||||
}
|
||||
}
|
||||
|
||||
void checkInited(int analysisMs){
|
||||
if(!_playResultCB){
|
||||
return;
|
||||
}
|
||||
@ -249,7 +273,8 @@ protected:
|
||||
protected:
|
||||
function<void(const SockException &ex)> _shutdownCB;
|
||||
function<void(const SockException &ex)> _playResultCB;
|
||||
std::shared_ptr<Parser> _parser;
|
||||
function<void()> _resumeCB;
|
||||
std::shared_ptr<Parser> _parser;
|
||||
MediaSource::Ptr _pMediaSrc;
|
||||
};
|
||||
|
||||
|
@ -117,30 +117,40 @@ void RtmpPlayer::onErr(const SockException &ex){
|
||||
|
||||
void RtmpPlayer::onPlayResult_l(const SockException &ex) {
|
||||
WarnL << ex.getErrCode() << " " << ex.what();
|
||||
|
||||
if(!ex){
|
||||
//恢复rtmp接收超时定时器
|
||||
_mediaTicker.resetTime();
|
||||
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
||||
_pMediaTimer.reset( new Timer(timeoutMS / 2000.0, [weakSelf,timeoutMS]() {
|
||||
auto strongSelf=weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return false;
|
||||
}
|
||||
if(strongSelf->_mediaTicker.elapsedTime()> timeoutMS) {
|
||||
//recv media timeout!
|
||||
strongSelf->onPlayResult_l(SockException(Err_timeout,"recv rtmp timeout"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},getPoller()));
|
||||
}
|
||||
|
||||
if (_pPlayTimer) {
|
||||
//开始播放阶段
|
||||
_pPlayTimer.reset();
|
||||
onPlayResult(ex);
|
||||
if(!ex){
|
||||
_mediaTicker.resetTime();
|
||||
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
||||
_pMediaTimer.reset( new Timer(timeoutMS / 2000.0, [weakSelf,timeoutMS]() {
|
||||
auto strongSelf=weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return false;
|
||||
}
|
||||
if(strongSelf->_mediaTicker.elapsedTime()> timeoutMS) {
|
||||
//recv media timeout!
|
||||
strongSelf->onPlayResult_l(SockException(Err_timeout,"recv rtmp timeout"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},getPoller()));
|
||||
}
|
||||
}else if(ex){
|
||||
//播放成功后异常断开回调
|
||||
onShutdown(ex);
|
||||
}
|
||||
}else {
|
||||
//播放中途阶段
|
||||
if (ex) {
|
||||
//播放成功后异常断开回调
|
||||
onShutdown(ex);
|
||||
}else{
|
||||
//恢复播放
|
||||
onResume();
|
||||
}
|
||||
}
|
||||
|
||||
if(ex){
|
||||
teardown();
|
||||
|
@ -614,36 +614,44 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pRtppt, const SdpTrack::Ptr &
|
||||
}
|
||||
void RtspPlayer::onPlayResult_l(const SockException &ex) {
|
||||
WarnL << ex.getErrCode() << " " << ex.what();
|
||||
if(_pPlayTimer){
|
||||
//播放结果回调
|
||||
_pPlayTimer.reset();
|
||||
onPlayResult(ex);
|
||||
if(!ex){
|
||||
//播放成功
|
||||
_rtpTicker.resetTime();
|
||||
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
||||
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
||||
_pRtpTimer.reset( new Timer(timeoutMS / 2000.0, [weakSelf,timeoutMS]() {
|
||||
auto strongSelf=weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return false;
|
||||
}
|
||||
if(strongSelf->_rtpTicker.elapsedTime()> timeoutMS) {
|
||||
//recv rtp timeout!
|
||||
strongSelf->onPlayResult_l(SockException(Err_timeout,"recv rtp timeout"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},getPoller()));
|
||||
}
|
||||
} else if(ex){
|
||||
//播放成功后异常断开回调
|
||||
onShutdown(ex);
|
||||
}
|
||||
|
||||
if(ex){
|
||||
teardown();
|
||||
}
|
||||
if(!ex){
|
||||
//播放成功,恢复rtp接收超时定时器
|
||||
_rtpTicker.resetTime();
|
||||
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
||||
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
||||
_pRtpTimer.reset( new Timer(timeoutMS / 2000.0, [weakSelf,timeoutMS]() {
|
||||
auto strongSelf=weakSelf.lock();
|
||||
if(!strongSelf) {
|
||||
return false;
|
||||
}
|
||||
if(strongSelf->_rtpTicker.elapsedTime()> timeoutMS) {
|
||||
//recv rtp timeout!
|
||||
strongSelf->onPlayResult_l(SockException(Err_timeout,"recv rtp timeout"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},getPoller()));
|
||||
}
|
||||
|
||||
if (_pPlayTimer) {
|
||||
//开始播放阶段
|
||||
_pPlayTimer.reset();
|
||||
onPlayResult(ex);
|
||||
}else {
|
||||
//播放中途阶段
|
||||
if (ex) {
|
||||
//播放成功后异常断开回调
|
||||
onShutdown(ex);
|
||||
}else{
|
||||
//恢复播放
|
||||
onResume();
|
||||
}
|
||||
}
|
||||
|
||||
if(ex){
|
||||
teardown();
|
||||
}
|
||||
}
|
||||
|
||||
int RtspPlayer::getTrackIndexByControlSuffix(const string &controlSuffix) const{
|
||||
|
Loading…
Reference in New Issue
Block a user