From b720ec7efffe90b64aefdab112593d4edacc879c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 9 Jun 2024 18:46:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emk=5Fproxy=5Fplayer=5Fset=5Fo?= =?UTF-8?q?n=5Fplay=5Fresult=E4=BB=A3=E7=90=86=E5=A4=B1=E8=B4=A5=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_proxyplayer.h | 17 ++++++++++++++--- api/source/mk_proxyplayer.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/api/include/mk_proxyplayer.h b/api/include/mk_proxyplayer.h index 1f66abc5..bbd4d14c 100644 --- a/api/include/mk_proxyplayer.h +++ b/api/include/mk_proxyplayer.h @@ -98,7 +98,9 @@ API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *u * 如果你不调用mk_proxy_player_release函数,那么MediaSource.close()操作将无效 * @param user_data 用户数据指针,通过mk_proxy_player_set_on_close函数设置 */ -typedef void(API_CALL *on_mk_proxy_player_close)(void *user_data, int err, const char *what, int sys_err); +typedef void(API_CALL *on_mk_proxy_player_cb)(void *user_data, int err, const char *what, int sys_err); +// 保持兼容 +#define on_mk_proxy_player_close on_mk_proxy_player_cb /** * 监听MediaSource.close()事件 @@ -108,8 +110,17 @@ typedef void(API_CALL *on_mk_proxy_player_close)(void *user_data, int err, const * @param cb 回调指针 * @param user_data 用户数据指针 */ -API_EXPORT void API_CALL mk_proxy_player_set_on_close(mk_proxy_player ctx, on_mk_proxy_player_close cb, void *user_data); -API_EXPORT void API_CALL mk_proxy_player_set_on_close2(mk_proxy_player ctx, on_mk_proxy_player_close cb, void *user_data, on_user_data_free user_data_free); +API_EXPORT void API_CALL mk_proxy_player_set_on_close(mk_proxy_player ctx, on_mk_proxy_player_cb cb, void *user_data); +API_EXPORT void API_CALL mk_proxy_player_set_on_close2(mk_proxy_player ctx, on_mk_proxy_player_cb cb, void *user_data, on_user_data_free user_data_free); + +/** + * 设置代理第一次播放结果回调,如果第一次播放失败,可以认作是启动失败 + * @param ctx 对象指针 + * @param cb 回调指针 + * @param user_data 用户数据指针 + * @param user_data_free 用户数据释放回调 + */ +API_EXPORT void API_CALL mk_proxy_player_set_on_play_result(mk_proxy_player ctx, on_mk_proxy_player_cb cb, void *user_data, on_user_data_free user_data_free); /** * 获取总的观看人数 diff --git a/api/source/mk_proxyplayer.cpp b/api/source/mk_proxyplayer.cpp index af73c013..90849304 100644 --- a/api/source/mk_proxyplayer.cpp +++ b/api/source/mk_proxyplayer.cpp @@ -84,6 +84,20 @@ API_EXPORT void API_CALL mk_proxy_player_set_on_close2(mk_proxy_player ctx, on_m }); } +API_EXPORT void API_CALL mk_proxy_player_set_on_play_result(mk_proxy_player ctx, on_mk_proxy_player_close cb, void *user_data, on_user_data_free user_data_free) { + assert(ctx); + PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *)ctx); + std::shared_ptr ptr(user_data, user_data_free ? user_data_free : [](void *) {}); + obj->getPoller()->async([obj, cb, ptr]() { + // 切换线程再操作 + obj->setPlayCallbackOnce([cb, ptr](const SockException &ex) { + if (cb) { + cb(ptr.get(), ex.getErrCode(), ex.what(), ex.getCustomCode()); + } + }); + }); +} + API_EXPORT int API_CALL mk_proxy_player_total_reader_count(mk_proxy_player ctx){ assert(ctx); PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);