mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +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 = PlayerBase::createPlayer(_poller,strUrl);
|
||||||
_parser->setOnShutdown(_shutdownCB);
|
_parser->setOnShutdown(_shutdownCB);
|
||||||
_parser->setOnPlayResult(_playResultCB);
|
_parser->setOnPlayResult(_playResultCB);
|
||||||
|
_parser->setOnResume(_resumeCB);
|
||||||
_parser->setMediaSouce(_pMediaSrc);
|
_parser->setMediaSouce(_pMediaSrc);
|
||||||
_parser->mINI::operator=(*this);
|
_parser->mINI::operator=(*this);
|
||||||
_parser->play(strUrl);
|
_parser->play(strUrl);
|
||||||
|
@ -120,6 +120,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void setOnPlayResult( const function<void(const SockException &ex)> &cb) {}
|
virtual void setOnPlayResult( const function<void(const SockException &ex)> &cb) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置播放恢复回调
|
||||||
|
* @param cb
|
||||||
|
*/
|
||||||
|
virtual void setOnResume( const function<void()> &cb) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取播放进度,取值 0.0 ~ 1.0
|
* 获取播放进度,取值 0.0 ~ 1.0
|
||||||
* @return
|
* @return
|
||||||
@ -147,6 +153,10 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void onShutdown(const SockException &ex) {}
|
virtual void onShutdown(const SockException &ex) {}
|
||||||
virtual void onPlayResult(const SockException &ex) {}
|
virtual void onPlayResult(const SockException &ex) {}
|
||||||
|
/**
|
||||||
|
* 暂停后恢复播放时间
|
||||||
|
*/
|
||||||
|
virtual void onResume(){};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Parent,typename Parser>
|
template<typename Parent,typename Parser>
|
||||||
@ -172,6 +182,13 @@ public:
|
|||||||
_playResultCB = cb;
|
_playResultCB = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setOnResume(const function<void()> &cb) override {
|
||||||
|
if (_parser) {
|
||||||
|
_parser->setOnResume(cb);
|
||||||
|
}
|
||||||
|
_resumeCB = cb;
|
||||||
|
}
|
||||||
|
|
||||||
bool isInited(int analysisMs) override{
|
bool isInited(int analysisMs) override{
|
||||||
if (_parser) {
|
if (_parser) {
|
||||||
return _parser->isInited(analysisMs);
|
return _parser->isInited(analysisMs);
|
||||||
@ -237,6 +254,13 @@ protected:
|
|||||||
}
|
}
|
||||||
//播放成功却未初始化完毕,这个时候不回调汇报播放成功
|
//播放成功却未初始化完毕,这个时候不回调汇报播放成功
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onResume() override{
|
||||||
|
if(_resumeCB){
|
||||||
|
_resumeCB();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void checkInited(int analysisMs){
|
void checkInited(int analysisMs){
|
||||||
if(!_playResultCB){
|
if(!_playResultCB){
|
||||||
return;
|
return;
|
||||||
@ -249,6 +273,7 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
function<void(const SockException &ex)> _shutdownCB;
|
function<void(const SockException &ex)> _shutdownCB;
|
||||||
function<void(const SockException &ex)> _playResultCB;
|
function<void(const SockException &ex)> _playResultCB;
|
||||||
|
function<void()> _resumeCB;
|
||||||
std::shared_ptr<Parser> _parser;
|
std::shared_ptr<Parser> _parser;
|
||||||
MediaSource::Ptr _pMediaSrc;
|
MediaSource::Ptr _pMediaSrc;
|
||||||
};
|
};
|
||||||
|
@ -117,10 +117,9 @@ void RtmpPlayer::onErr(const SockException &ex){
|
|||||||
|
|
||||||
void RtmpPlayer::onPlayResult_l(const SockException &ex) {
|
void RtmpPlayer::onPlayResult_l(const SockException &ex) {
|
||||||
WarnL << ex.getErrCode() << " " << ex.what();
|
WarnL << ex.getErrCode() << " " << ex.what();
|
||||||
if (_pPlayTimer) {
|
|
||||||
_pPlayTimer.reset();
|
|
||||||
onPlayResult(ex);
|
|
||||||
if(!ex){
|
if(!ex){
|
||||||
|
//恢复rtmp接收超时定时器
|
||||||
_mediaTicker.resetTime();
|
_mediaTicker.resetTime();
|
||||||
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||||
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
||||||
@ -137,9 +136,20 @@ void RtmpPlayer::onPlayResult_l(const SockException &ex) {
|
|||||||
return true;
|
return true;
|
||||||
},getPoller()));
|
},getPoller()));
|
||||||
}
|
}
|
||||||
}else if(ex){
|
|
||||||
|
if (_pPlayTimer) {
|
||||||
|
//开始播放阶段
|
||||||
|
_pPlayTimer.reset();
|
||||||
|
onPlayResult(ex);
|
||||||
|
}else {
|
||||||
|
//播放中途阶段
|
||||||
|
if (ex) {
|
||||||
//播放成功后异常断开回调
|
//播放成功后异常断开回调
|
||||||
onShutdown(ex);
|
onShutdown(ex);
|
||||||
|
}else{
|
||||||
|
//恢复播放
|
||||||
|
onResume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ex){
|
if(ex){
|
||||||
|
@ -614,12 +614,9 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &pRtppt, const SdpTrack::Ptr &
|
|||||||
}
|
}
|
||||||
void RtspPlayer::onPlayResult_l(const SockException &ex) {
|
void RtspPlayer::onPlayResult_l(const SockException &ex) {
|
||||||
WarnL << ex.getErrCode() << " " << ex.what();
|
WarnL << ex.getErrCode() << " " << ex.what();
|
||||||
if(_pPlayTimer){
|
|
||||||
//播放结果回调
|
|
||||||
_pPlayTimer.reset();
|
|
||||||
onPlayResult(ex);
|
|
||||||
if(!ex){
|
if(!ex){
|
||||||
//播放成功
|
//播放成功,恢复rtp接收超时定时器
|
||||||
_rtpTicker.resetTime();
|
_rtpTicker.resetTime();
|
||||||
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
||||||
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
int timeoutMS = (*this)[kMediaTimeoutMS].as<int>();
|
||||||
@ -636,9 +633,20 @@ void RtspPlayer::onPlayResult_l(const SockException &ex) {
|
|||||||
return true;
|
return true;
|
||||||
},getPoller()));
|
},getPoller()));
|
||||||
}
|
}
|
||||||
} else if(ex){
|
|
||||||
|
if (_pPlayTimer) {
|
||||||
|
//开始播放阶段
|
||||||
|
_pPlayTimer.reset();
|
||||||
|
onPlayResult(ex);
|
||||||
|
}else {
|
||||||
|
//播放中途阶段
|
||||||
|
if (ex) {
|
||||||
//播放成功后异常断开回调
|
//播放成功后异常断开回调
|
||||||
onShutdown(ex);
|
onShutdown(ex);
|
||||||
|
}else{
|
||||||
|
//恢复播放
|
||||||
|
onResume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ex){
|
if(ex){
|
||||||
|
Loading…
Reference in New Issue
Block a user