From 92f3ecc94e1bc5a67e28c56b127df8f765da0386 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 18 Jan 2025 10:44:02 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E5=BD=95=E9=9F=B3=E6=92=AD?= =?utf8?q?=E6=94=BE=E5=87=BD=E6=95=B0=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9D=A1?= =?utf8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E6=8F=90=E9=AB=98=E4=BB=A3=E7=A0=81?= =?utf8?q?=E5=81=A5=E5=A3=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/record/src/RecordingModel.cpp | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp index dd797c0e7..9b578e267 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingModel.cpp @@ -246,6 +246,12 @@ namespace OHOS // 设置回调函数 PlayerCtr->SetPlayerCallback(PlayerCallback); + // 添加条件判断,确保uri必须为MP3格式 + if (Uri.find(".mp3") == std::string::npos) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid file format. Only MP3 files are supported."); + return OHOS_FAILURE; + } // 申请资源 Resource = std::make_shared(Uri, Header); if (Resource.get() == nullptr) @@ -253,9 +259,21 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Resource new fail"); return OHOS_FAILURE; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Player uri %s.", Uri.c_str()); - PlayerCtr->SetSource(*Resource); - PlayerCtr->Prepare(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Player uri %s.", Uri.c_str()); + ret = PlayerCtr->SetSource(*Resource); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetSource fail"); + PlayerCtr->Reset(); + return OHOS_FAILURE; + } + ret = PlayerCtr->Prepare(); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Prepare fail"); + PlayerCtr->Reset(); + return OHOS_FAILURE; + } ret = PlayerCtr->GetDuration(DurationTime); ConvertMillisecondToTime(DurationTime); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%s,%d] GetDuration:%lld,%s, ret:%d", __func__, __LINE__, DurationTime, TotalRecordDuration.c_str(), ret); @@ -287,7 +305,13 @@ namespace OHOS } IsActivateAudioInterrupt = true; } - PlayerCtr->SetAudioSessionId(SessionId); + ret = PlayerCtr->SetAudioSessionId(SessionId); + if (ret != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetAudioSessionId faild"); + PlayerCtr->Reset(); + return OHOS_FAILURE; + } // 播放 ret = PlayerCtr->Play(); if (ret != 0) -- 2.17.1