From 4fa04d6a370eb4787de21ef55ad108fed63b34b5 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 13 May 2023 00:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96PlayerProxy=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Player/PlayerProxy.cpp | 15 +++++++-------- src/Player/PlayerProxy.h | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) 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