1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ci 16e1c44949Sopenharmony_ci#include "sound.h" 17e1c44949Sopenharmony_ci 18e1c44949Sopenharmony_ci#include <thread> 19e1c44949Sopenharmony_ci 20e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h" 21e1c44949Sopenharmony_ci 22e1c44949Sopenharmony_cinamespace OHOS { 23e1c44949Sopenharmony_cinamespace Telephony { 24e1c44949Sopenharmony_ciSound::Sound() : audioPlayer_(new (std::nothrow) AudioPlayer()) {} 25e1c44949Sopenharmony_ci 26e1c44949Sopenharmony_ciSound::~Sound() 27e1c44949Sopenharmony_ci{ 28e1c44949Sopenharmony_ci if (audioPlayer_ != nullptr) { 29e1c44949Sopenharmony_ci delete audioPlayer_; 30e1c44949Sopenharmony_ci audioPlayer_ = nullptr; 31e1c44949Sopenharmony_ci } 32e1c44949Sopenharmony_ci} 33e1c44949Sopenharmony_ci 34e1c44949Sopenharmony_ciint32_t Sound::Play() 35e1c44949Sopenharmony_ci{ 36e1c44949Sopenharmony_ci if (audioPlayer_ == nullptr) { 37e1c44949Sopenharmony_ci TELEPHONY_LOGE("audioPlayer_ is nullptr"); 38e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 39e1c44949Sopenharmony_ci } 40e1c44949Sopenharmony_ci return audioPlayer_->Play(TYPE_SOUND); 41e1c44949Sopenharmony_ci} 42e1c44949Sopenharmony_ci 43e1c44949Sopenharmony_ciint32_t Sound::Stop() 44e1c44949Sopenharmony_ci{ 45e1c44949Sopenharmony_ci if (audioPlayer_ == nullptr) { 46e1c44949Sopenharmony_ci TELEPHONY_LOGE("audioPlayer_ is nullptr"); 47e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 48e1c44949Sopenharmony_ci } 49e1c44949Sopenharmony_ci audioPlayer_->SetStop(PlayerType::TYPE_SOUND, true); 50e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 51e1c44949Sopenharmony_ci} 52e1c44949Sopenharmony_ci 53e1c44949Sopenharmony_civoid Sound::ReleaseRenderer() 54e1c44949Sopenharmony_ci{ 55e1c44949Sopenharmony_ci if (audioPlayer_ == nullptr) { 56e1c44949Sopenharmony_ci TELEPHONY_LOGE("audioPlayer_ is nullptr"); 57e1c44949Sopenharmony_ci return; 58e1c44949Sopenharmony_ci } 59e1c44949Sopenharmony_ci audioPlayer_->ReleaseRenderer(); 60e1c44949Sopenharmony_ci audioPlayer_->ReleaseCapturer(); 61e1c44949Sopenharmony_ci} 62e1c44949Sopenharmony_ci} // namespace Telephony 63e1c44949Sopenharmony_ci} // namespace OHOS