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 "ringtone_player_impl.h"
17
18 #include <sys/stat.h>
19
20 #include "media_log.h"
21 #include "media_errors.h"
22
23 using namespace std;
24 using namespace OHOS::AbilityRuntime;
25
26 namespace {
27 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO_NAPI, "RingtonePlayer"};
28 }
29
30 namespace OHOS {
31 namespace Media {
32 const int32_t ERRCODE_IOERROR = 5400103;
33 const float HIGH_VOL = 1.0f;
34 const float LOW_VOL = 0.0f;
35 const std::string AUDIO_FORMAT_STR = ".ogg";
36 const std::string HAPTIC_FORMAT_STR = ".json";
37 const std::string RINGTONE_PATH = "/media/audio/";
38 const std::string STANDARD_HAPTICS_PATH = "/media/haptics/standard/synchronized/";
39
RingtonePlayerImpl(const shared_ptr<Context> & context,SystemSoundManagerImpl & sysSoundMgr,RingtoneType type)40 RingtonePlayerImpl::RingtonePlayerImpl(const shared_ptr<Context> &context,
41 SystemSoundManagerImpl &sysSoundMgr, RingtoneType type)
42 : volume_(HIGH_VOL),
43 loop_(false),
44 context_(context),
45 systemSoundMgr_(sysSoundMgr),
46 type_(type)
47 {
48 audioHapticManager_ = AudioHapticManagerFactory::CreateAudioHapticManager();
49 CHECK_AND_RETURN_LOG(audioHapticManager_ != nullptr, "Failed to get audio haptic manager");
50
51 if (InitDataShareHelper()) {
52 std::string ringtoneUri = systemSoundMgr_.GetRingtoneUri(context_, type_);
53 AudioHapticPlayerOptions options = {false, false};
54 ToneHapticsSettings settings = GetHapticSettings(ringtoneUri, options.muteHaptics);
55 InitPlayer(ringtoneUri, settings, options);
56 ReleaseDataShareHelper();
57 }
58 }
59
~RingtonePlayerImpl()60 RingtonePlayerImpl::~RingtonePlayerImpl()
61 {
62 if (player_ != nullptr) {
63 player_->Release();
64 (void)SystemSoundVibrator::StopVibrator();
65 player_ = nullptr;
66 callback_ = nullptr;
67 }
68 if (audioHapticManager_ != nullptr) {
69 (void)audioHapticManager_->UnregisterSource(sourceId_);
70 audioHapticManager_ = nullptr;
71 }
72 ReleaseDataShareHelper();
73 }
74
IsFileExisting(const std::string & fileUri)75 bool RingtonePlayerImpl::IsFileExisting(const std::string &fileUri)
76 {
77 struct stat buffer;
78 return (stat(fileUri.c_str(), &buffer) == 0);
79 }
80
GetNewHapticUriForAudioUri(const std::string & audioUri,const std::string & ringtonePath,const std::string & hapticsPath)81 std::string RingtonePlayerImpl::GetNewHapticUriForAudioUri(const std::string &audioUri,
82 const std::string &ringtonePath, const std::string& hapticsPath)
83 {
84 string hapticUri = audioUri;
85 size_t pos = hapticUri.find(ringtonePath);
86 if (pos == string::npos) {
87 return "";
88 }
89 hapticUri.replace(pos, ringtonePath.size(), hapticsPath);
90 if (hapticUri.length() > AUDIO_FORMAT_STR.length() &&
91 hapticUri.rfind(AUDIO_FORMAT_STR) == hapticUri.length() - AUDIO_FORMAT_STR.length()) {
92 hapticUri.replace(hapticUri.rfind(AUDIO_FORMAT_STR), AUDIO_FORMAT_STR.length(), HAPTIC_FORMAT_STR);
93 if (IsFileExisting(hapticUri)) {
94 return hapticUri;
95 }
96 }
97 return "";
98 }
99
GetNewHapticUriForAudioUri(const std::string & audioUri)100 std::string RingtonePlayerImpl::GetNewHapticUriForAudioUri(const std::string &audioUri)
101 {
102 std::string hapticUri = GetNewHapticUriForAudioUri(audioUri, RINGTONE_PATH, STANDARD_HAPTICS_PATH);
103 if (hapticUri.empty()) {
104 MEDIA_LOGW("Failed to find the vibration json file for audioUri. Use the default json file.");
105 std::string currAudioUri = systemSoundMgr_.GetDefaultRingtoneUri(RINGTONE_TYPE_SIM_CARD_0);
106 return GetNewHapticUriForAudioUri(currAudioUri, RINGTONE_PATH, STANDARD_HAPTICS_PATH);
107 }
108 return hapticUri;
109 }
110
GetHapticUriForAudioUri(const std::string & audioUri)111 std::string RingtonePlayerImpl::GetHapticUriForAudioUri(const std::string &audioUri)
112 {
113 std::string hapticUri = "";
114 if (audioUri.length() > AUDIO_FORMAT_STR.length() &&
115 audioUri.rfind(AUDIO_FORMAT_STR) == audioUri.length() - AUDIO_FORMAT_STR.length()) {
116 // the end of audio uri is ".ogg"
117 hapticUri = audioUri;
118 hapticUri.replace(hapticUri.rfind(AUDIO_FORMAT_STR), AUDIO_FORMAT_STR.length(), HAPTIC_FORMAT_STR);
119 }
120
121 if (hapticUri == "" || !IsFileExisting(hapticUri)) {
122 MEDIA_LOGW("Failed to find the vibration json file for audioUri. Use the default json file.");
123 std::string defaultRingtoneUri = systemSoundMgr_.GetDefaultRingtoneUri(RINGTONE_TYPE_SIM_CARD_0);
124 if (defaultRingtoneUri.length() > AUDIO_FORMAT_STR.length() &&
125 defaultRingtoneUri.rfind(AUDIO_FORMAT_STR) == defaultRingtoneUri.length() - AUDIO_FORMAT_STR.length()) {
126 // the end of default ringtone uri is ".ogg"
127 hapticUri = defaultRingtoneUri;
128 hapticUri.replace(hapticUri.rfind(AUDIO_FORMAT_STR), AUDIO_FORMAT_STR.length(), HAPTIC_FORMAT_STR);
129 } else {
130 MEDIA_LOGW("The default ringtone uri is invalid!");
131 }
132 }
133
134 return hapticUri;
135 }
136
CreateDataShareHelper(int32_t systemAbilityId)137 static shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(int32_t systemAbilityId)
138 {
139 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
140 if (saManager == nullptr) {
141 return nullptr;
142 }
143 auto remoteObj = saManager->GetSystemAbility(systemAbilityId);
144 if (remoteObj == nullptr) {
145 return nullptr;
146 }
147 return DataShare::DataShareHelper::Creator(remoteObj, RINGTONE_URI);
148 }
149
InitDataShareHelper()150 bool RingtonePlayerImpl::InitDataShareHelper()
151 {
152 MEDIA_LOGD("Enter InitDataShareHelper()");
153 ReleaseDataShareHelper();
154 dataShareHelper_ = CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID);
155 CHECK_AND_RETURN_RET_LOG(dataShareHelper_ != nullptr, false, "Failed to create dataShareHelper.");
156 return true;
157 }
158
ReleaseDataShareHelper()159 void RingtonePlayerImpl::ReleaseDataShareHelper()
160 {
161 if (dataShareHelper_ != nullptr) {
162 MEDIA_LOGD("Enter ReleaseDataShareHelper()");
163 dataShareHelper_->Release();
164 dataShareHelper_ = nullptr;
165 }
166 }
167
ChangeUri(const std::string & audioUri)168 std::string RingtonePlayerImpl::ChangeUri(const std::string &audioUri)
169 {
170 const std::string FDHEAD = "fd://";
171 std::string ringtoneUri = audioUri;
172 CHECK_AND_RETURN_RET_LOG(dataShareHelper_ != nullptr, ringtoneUri, "Failed to init dataShareHelper_.");
173
174 DataShare::DatashareBusinessError businessError;
175 DataShare::DataSharePredicates queryPredicates;
176 Uri ringtonePathUri(RINGTONE_PATH_URI);
177 vector<string> columns = {{RINGTONE_COLUMN_TONE_ID}, {RINGTONE_COLUMN_DATA}};
178 queryPredicates.EqualTo(RINGTONE_COLUMN_DATA, audioUri);
179 auto resultSet = dataShareHelper_->Query(ringtonePathUri, queryPredicates, columns, &businessError);
180 auto results = make_unique<RingtoneFetchResult<RingtoneAsset>>(move(resultSet));
181 unique_ptr<RingtoneAsset> ringtoneAsset = results->GetFirstObject();
182 if (ringtoneAsset != nullptr) {
183 string uriStr = RINGTONE_PATH_URI + RINGTONE_SLASH_CHAR + to_string(ringtoneAsset->GetId());
184 MEDIA_LOGD("ChangeUri::Open ringtoneUri is %{public}s", uriStr.c_str());
185 Uri ofUri(uriStr);
186 int32_t fd = dataShareHelper_->OpenFile(ofUri, "r");
187 if (fd > 0) {
188 ringtoneUri = FDHEAD + to_string(fd);
189 }
190 }
191
192 resultSet == nullptr ? : resultSet->Close();
193 MEDIA_LOGI("RingtonePlayerImpl::ChangeUri ringtoneUri is %{public}s", ringtoneUri.c_str());
194 return ringtoneUri;
195 }
196
ChangeHapticsUri(const std::string & hapticsUri)197 std::string RingtonePlayerImpl::ChangeHapticsUri(const std::string &hapticsUri)
198 {
199 const std::string FDHEAD = "fd://";
200 std::string newHapticsUri = hapticsUri;
201 CHECK_AND_RETURN_RET_LOG(dataShareHelper_ != nullptr, newHapticsUri, "Failed to create dataShareHelper.");
202
203 DataShare::DatashareBusinessError businessError;
204 DataShare::DataSharePredicates queryPredicates;
205 Uri hapticsPathUri(VIBRATE_PATH_URI);
206 vector<string> columns = {{VIBRATE_COLUMN_VIBRATE_ID}, {VIBRATE_COLUMN_DATA}};
207 queryPredicates.EqualTo(RINGTONE_COLUMN_DATA, hapticsUri);
208 auto resultSet = dataShareHelper_->Query(hapticsPathUri, queryPredicates, columns, &businessError);
209 auto results = make_unique<RingtoneFetchResult<VibrateAsset>>(move(resultSet));
210
211 unique_ptr<VibrateAsset> vibrateAssetByUri = results->GetFirstObject();
212 if (vibrateAssetByUri != nullptr) {
213 string uriStr = VIBRATE_PATH_URI + RINGTONE_SLASH_CHAR + to_string(vibrateAssetByUri->GetId());
214 MEDIA_LOGD("ChangeHapticsUri::Open newHapticsUri is %{public}s", uriStr.c_str());
215 Uri ofUri(uriStr);
216 int32_t fd = dataShareHelper_->OpenFile(ofUri, "r");
217 if (fd > 0) {
218 newHapticsUri = FDHEAD + to_string(fd);
219 }
220 }
221
222 resultSet == nullptr ? : resultSet->Close();
223 MEDIA_LOGI("RingtonePlayerImpl::ChangeHapticsUri newHapticsUri is %{public}s", newHapticsUri.c_str());
224 return newHapticsUri;
225 }
226
ConvertToToneHapticsType(RingtoneType type)227 ToneHapticsType RingtonePlayerImpl::ConvertToToneHapticsType(RingtoneType type)
228 {
229 switch (type) {
230 case RingtoneType::RINGTONE_TYPE_SIM_CARD_0:
231 return ToneHapticsType::CALL_SIM_CARD_0;
232 case RingtoneType::RINGTONE_TYPE_SIM_CARD_1:
233 return ToneHapticsType::CALL_SIM_CARD_1;
234 default:
235 return ToneHapticsType::CALL_SIM_CARD_0;
236 }
237 }
238
ConvertToHapticsMode(ToneHapticsMode toneHapticsMode)239 HapticsMode RingtonePlayerImpl::ConvertToHapticsMode(ToneHapticsMode toneHapticsMode)
240 {
241 switch (toneHapticsMode) {
242 case ToneHapticsMode::NONE:
243 return HapticsMode::HAPTICS_MODE_NONE;
244 case ToneHapticsMode::SYNC:
245 return HapticsMode::HAPTICS_MODE_SYNC;
246 case ToneHapticsMode::NON_SYNC:
247 return HapticsMode::HAPTICS_MODE_NON_SYNC;
248 default:
249 return HapticsMode::HAPTICS_MODE_INVALID;
250 }
251 }
252
GetHapticSettings(std::string & audioUri,bool & muteHaptics)253 ToneHapticsSettings RingtonePlayerImpl::GetHapticSettings(std::string &audioUri, bool &muteHaptics)
254 {
255 ToneHapticsSettings settings;
256 int32_t result = systemSoundMgr_.GetToneHapticsSettings(dataShareHelper_, audioUri,
257 ConvertToToneHapticsType(type_), settings);
258 if (result == 0) {
259 MEDIA_LOGI("GetHapticSettings: hapticsUri:%{public}s, mode:%{public}d.",
260 settings.hapticsUri.c_str(), settings.mode);
261 return settings;
262 }
263 settings.mode = ToneHapticsMode::SYNC;
264 settings.hapticsUri = GetNewHapticUriForAudioUri(audioUri);
265 if (settings.hapticsUri.empty()) {
266 settings.hapticsUri = GetHapticUriForAudioUri(audioUri);
267 if (settings.hapticsUri.empty()) {
268 MEDIA_LOGW("haptic uri is empty. Play ringtone without vibration");
269 muteHaptics = true;
270 settings.mode = ToneHapticsMode::NONE;
271 }
272 }
273 MEDIA_LOGI("GetHapticSettings: hapticsUri:%{public}s, mode:%{public}d.",
274 settings.hapticsUri.c_str(), settings.mode);
275 return settings;
276 }
277
RegisterSource(const std::string & audioUri,const std::string & hapticUri)278 int32_t RingtonePlayerImpl::RegisterSource(const std::string &audioUri, const std::string &hapticUri)
279 {
280 string newAudioUri = ChangeUri(audioUri);
281 string newHapticUri = ChangeHapticsUri(hapticUri);
282
283 int32_t sourceId = audioHapticManager_->RegisterSource(newAudioUri, newHapticUri);
284
285 const std::string fdHead = "fd://";
286 if (newAudioUri.find(fdHead) != std::string::npos) {
287 int32_t fd = atoi(newAudioUri.substr(fdHead.size()).c_str());
288 if (fd > 0) {
289 close(fd);
290 }
291 }
292 if (newHapticUri.find(fdHead) != std::string::npos) {
293 int32_t fd = atoi(newHapticUri.substr(fdHead.size()).c_str());
294 if (fd > 0) {
295 close(fd);
296 }
297 }
298
299 return sourceId;
300 }
301
InitPlayer(std::string & audioUri,ToneHapticsSettings & settings,AudioHapticPlayerOptions options)302 void RingtonePlayerImpl::InitPlayer(std::string &audioUri, ToneHapticsSettings &settings,
303 AudioHapticPlayerOptions options)
304 {
305 MEDIA_LOGI("InitPlayer: ToneUri:%{public}s, hapticsUri:%{public}s, mode:%{public}d.",
306 audioUri.c_str(), settings.hapticsUri.c_str(), settings.mode);
307 if (sourceId_ != -1) {
308 (void)audioHapticManager_->UnregisterSource(sourceId_);
309 sourceId_ = -1;
310 }
311
312 sourceId_ = RegisterSource(audioUri, settings.hapticsUri);
313 CHECK_AND_RETURN_LOG(sourceId_ != -1, "Failed to register source for audio haptic manager");
314 (void)audioHapticManager_->SetAudioLatencyMode(sourceId_, AUDIO_LATENCY_MODE_NORMAL);
315 (void)audioHapticManager_->SetStreamUsage(sourceId_, AudioStandard::StreamUsage::STREAM_USAGE_VOICE_RINGTONE);
316
317 bool hapticsSwitchStatus = systemSoundMgr_.CheckVibrateSwitchStatus();
318 AudioStandard::AudioRingerMode ringerMode = systemSoundMgr_.GetRingerMode();
319 if (ringerMode == AudioStandard::AudioRingerMode::RINGER_MODE_SILENT ||
320 (ringerMode == AudioStandard::AudioRingerMode::RINGER_MODE_NORMAL && !hapticsSwitchStatus)) {
321 options.muteHaptics = true;
322 }
323 player_ = audioHapticManager_->CreatePlayer(sourceId_, options);
324 CHECK_AND_RETURN_LOG(player_ != nullptr, "Failed to create ringtone player instance");
325 player_->SetHapticsMode(ConvertToHapticsMode(settings.mode));
326 int32_t result = player_->Prepare();
327 CHECK_AND_RETURN_LOG(result == MSERR_OK, "Failed to load source for audio haptic manager");
328 configuredUri_ = audioUri;
329 configuredHaptcisSettings_ = settings;
330
331 if (callback_ == nullptr) {
332 callback_ = std::make_shared<RingtonePlayerCallback>(*this);
333 }
334 CHECK_AND_RETURN_LOG(callback_ != nullptr, "Failed to create callback object");
335 (void)player_->SetAudioHapticPlayerCallback(callback_);
336 (void)player_->SetVolume(volume_);
337 (void)player_->SetLoop(loop_);
338
339 ringtoneState_ = STATE_NEW;
340 }
341
Configure(const float & volume,const bool & loop)342 int32_t RingtonePlayerImpl::Configure(const float &volume, const bool &loop)
343 {
344 MEDIA_LOGI("RingtonePlayerImpl::Configure with volume %{public}f, loop %{public}d", volume, loop);
345 CHECK_AND_RETURN_RET_LOG(volume >= LOW_VOL && volume <= HIGH_VOL,
346 MSERR_INVALID_VAL, "Volume level invalid");
347
348 std::lock_guard<std::mutex> lock(playerMutex_);
349 CHECK_AND_RETURN_RET_LOG(player_ != nullptr && ringtoneState_ != STATE_INVALID, MSERR_INVALID_VAL, "no player_");
350 volume_ = volume;
351 loop_ = loop;
352 (void)player_->SetVolume(volume_);
353 (void)player_->SetLoop(loop_);
354
355 return MSERR_OK;
356 }
357
Start()358 int32_t RingtonePlayerImpl::Start()
359 {
360 MEDIA_LOGI("RingtonePlayerImpl::Start");
361 std::lock_guard<std::mutex> lock(playerMutex_);
362 CHECK_AND_RETURN_RET_LOG(ringtoneState_ != STATE_RUNNING, MSERR_INVALID_OPERATION, "ringtone player is running");
363 CHECK_AND_RETURN_RET_LOG(player_ != nullptr && ringtoneState_ != STATE_INVALID, MSERR_INVALID_VAL, "no player_");
364
365 if (!InitDataShareHelper()) {
366 return ERRCODE_IOERROR;
367 }
368 std::string ringtoneUri = systemSoundMgr_.GetRingtoneUri(context_, type_);
369 AudioHapticPlayerOptions options = {false, false};
370 ToneHapticsSettings settings = GetHapticSettings(ringtoneUri, options.muteHaptics);
371 if (ringtoneUri != configuredUri_ || settings.hapticsUri != configuredHaptcisSettings_.hapticsUri ||
372 settings.mode != configuredHaptcisSettings_.mode) {
373 MEDIA_LOGI("Ringtone uri changed. Reload player");
374 InitPlayer(ringtoneUri, settings, options);
375 }
376 ReleaseDataShareHelper();
377 int32_t ret = player_->Start();
378 CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_START_FAILED, "Start failed %{public}d", ret);
379 ringtoneState_ = STATE_RUNNING;
380
381 return MSERR_OK;
382 }
383
Stop()384 int32_t RingtonePlayerImpl::Stop()
385 {
386 MEDIA_LOGI("RingtonePlayerImpl::Stop");
387 std::lock_guard<std::mutex> lock(playerMutex_);
388 CHECK_AND_RETURN_RET_LOG(ringtoneState_ != STATE_STOPPED, MSERR_INVALID_OPERATION,
389 "ringtone player has been stopped");
390 CHECK_AND_RETURN_RET_LOG(player_ != nullptr && ringtoneState_ != STATE_INVALID, MSERR_INVALID_VAL, "no player_");
391
392 (void)player_->Stop();
393 ringtoneState_ = STATE_STOPPED;
394
395 return MSERR_OK;
396 }
397
Release()398 int32_t RingtonePlayerImpl::Release()
399 {
400 MEDIA_LOGI("RingtonePlayerImpl::Release");
401 std::lock_guard<std::mutex> lock(playerMutex_);
402 CHECK_AND_RETURN_RET_LOG(ringtoneState_ != STATE_RELEASED, MSERR_INVALID_OPERATION,
403 "ringtone player has been released");
404 CHECK_AND_RETURN_RET_LOG(player_ != nullptr && ringtoneState_ != STATE_INVALID, MSERR_INVALID_VAL, "no player_");
405
406 (void)player_->Release();
407 player_ = nullptr;
408 callback_ = nullptr;
409
410 if (audioHapticManager_ != nullptr) {
411 (void)audioHapticManager_->UnregisterSource(sourceId_);
412 audioHapticManager_ = nullptr;
413 }
414 configuredUri_ = "";
415
416 ringtoneState_ = STATE_RELEASED;
417 return MSERR_OK;
418 }
419
GetRingtoneState()420 RingtoneState RingtonePlayerImpl::GetRingtoneState()
421 {
422 MEDIA_LOGI("RingtonePlayerImpl::GetRingtoneState");
423 std::lock_guard<std::mutex> lock(playerMutex_);
424 return ringtoneState_;
425 }
426
GetAudioRendererInfo(AudioStandard::AudioRendererInfo & rendererInfo) const427 int32_t RingtonePlayerImpl::GetAudioRendererInfo(AudioStandard::AudioRendererInfo &rendererInfo) const
428 {
429 MEDIA_LOGI("RingtonePlayerImpl::GetAudioRendererInfo");
430 rendererInfo.contentType = AudioStandard::ContentType::CONTENT_TYPE_UNKNOWN;
431 rendererInfo.streamUsage = AudioStandard::StreamUsage::STREAM_USAGE_RINGTONE;
432 rendererInfo.rendererFlags = 0;
433 return MSERR_OK;
434 }
435
GetTitle()436 std::string RingtonePlayerImpl::GetTitle()
437 {
438 MEDIA_LOGI("RingtonePlayerImpl::GetTitle");
439 CHECK_AND_RETURN_RET_LOG(configuredUri_ != "", "", "Configured uri is null");
440 return systemSoundMgr_.GetRingtoneTitle(configuredUri_);
441 }
442
SetRingtonePlayerInterruptCallback(const std::shared_ptr<RingtonePlayerInterruptCallback> & interruptCallback)443 int32_t RingtonePlayerImpl::SetRingtonePlayerInterruptCallback(
444 const std::shared_ptr<RingtonePlayerInterruptCallback> &interruptCallback)
445 {
446 MEDIA_LOGI("RingtonePlayerImpl::SetRingtonePlayerInterruptCallback");
447 std::lock_guard<std::mutex> lock(playerMutex_);
448 interruptCallback_ = interruptCallback;
449 return MSERR_OK;
450 }
451
NotifyEndofStreamEvent()452 void RingtonePlayerImpl::NotifyEndofStreamEvent()
453 {
454 std::lock_guard<std::mutex> lock(playerMutex_);
455 ringtoneState_ = RingtoneState::STATE_STOPPED;
456 }
457
NotifyInterruptEvent(const AudioStandard::InterruptEvent & interruptEvent)458 void RingtonePlayerImpl::NotifyInterruptEvent(const AudioStandard::InterruptEvent &interruptEvent)
459 {
460 if (interruptCallback_ != nullptr) {
461 interruptCallback_->OnInterrupt(interruptEvent);
462 MEDIA_LOGI("RingtonePlayerImpl::NotifyInterruptEvent");
463 } else {
464 MEDIA_LOGE("RingtonePlayerImpl::interruptCallback_ is nullptr");
465 }
466 }
467
468 // Callback class symbols
RingtonePlayerCallback(RingtonePlayerImpl & ringtonePlayerImpl)469 RingtonePlayerCallback::RingtonePlayerCallback(RingtonePlayerImpl &ringtonePlayerImpl)
470 : ringtonePlayerImpl_(ringtonePlayerImpl) {}
471
OnInterrupt(const AudioStandard::InterruptEvent & interruptEvent)472 void RingtonePlayerCallback::OnInterrupt(const AudioStandard::InterruptEvent &interruptEvent)
473 {
474 MEDIA_LOGI("RingtonePlayerCallback::OnInterrupt: hintTye %{public}d", interruptEvent.hintType);
475 ringtonePlayerImpl_.NotifyInterruptEvent(interruptEvent);
476 }
477
OnEndOfStream(void)478 void RingtonePlayerCallback::OnEndOfStream(void)
479 {
480 MEDIA_LOGI("RingtonePlayerCallback::OnEndOfStream");
481 ringtonePlayerImpl_.NotifyEndofStreamEvent();
482 }
483
OnError(int32_t errorCode)484 void RingtonePlayerCallback::OnError(int32_t errorCode)
485 {
486 MEDIA_LOGI("OnError from audio haptic player. errorCode %{public}d", errorCode);
487 }
488 } // namesapce AudioStandard
489 } // namespace OHOS
490