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