diff --git a/src/Player/PlayerProxy.cpp b/src/Player/PlayerProxy.cpp index 5bdb3083..d1f414d3 100644 --- a/src/Player/PlayerProxy.cpp +++ b/src/Player/PlayerProxy.cpp @@ -34,6 +34,7 @@ PlayerProxy::PlayerProxy( _stream_id = stream_id; _retry_count = retry_count; + setOnClose(nullptr); setOnConnect(nullptr); setOnDisconnect(nullptr); @@ -43,16 +44,15 @@ PlayerProxy::PlayerProxy( _live_secs = 0; _live_status = 1; _repull_count = 0; - _on_close = [](const SockException &) {}; (*this)[Client::kWaitTrackReady] = false; } -void PlayerProxy::setPlayCallbackOnce(const function &cb) { - _on_play = cb; +void PlayerProxy::setPlayCallbackOnce(function cb) { + _on_play = std::move(cb); } -void PlayerProxy::setOnClose(const function &cb) { - _on_close = cb ? cb : [](const SockException &) {}; +void PlayerProxy::setOnClose(function cb) { + _on_close = cb ? std::move(cb) : [](const SockException &) {}; } void PlayerProxy::setOnDisconnect(std::function cb) { @@ -174,7 +174,7 @@ void PlayerProxy::play(const string &strUrlTmp) { MediaPlayer::play(strUrlTmp); } catch (std::exception &ex) { ErrorL << ex.what(); - _on_play_result(SockException(Err_other, ex.what())); + onPlayResult(SockException(Err_other, ex.what())); return; } _pull_url = strUrlTmp; @@ -324,9 +324,8 @@ int PlayerProxy::getStatus() { uint64_t PlayerProxy::getLiveSecs() { if (_live_status == 0) { return _live_secs + _live_ticker.elapsedTime() / 1000; - } else { - return _live_secs; } + return _live_secs; } uint64_t PlayerProxy::getRePullCount() { diff --git a/src/Player/PlayerProxy.h b/src/Player/PlayerProxy.h index 1ed625c6..9cf621da 100644 --- a/src/Player/PlayerProxy.h +++ b/src/Player/PlayerProxy.h @@ -76,13 +76,13 @@ public: * 设置play结果回调,只触发一次;在play执行之前有效 * @param cb 回调对象 */ - void setPlayCallbackOnce(const std::function &cb); + void setPlayCallbackOnce(std::function cb); /** * 设置主动关闭回调 * @param cb 回调对象 */ - void setOnClose(const std::function &cb); + void setOnClose(std::function cb); /** * Set a callback for failed server connection