Skip to content

Commit 91ad6da

Browse files
authored
Add support for avplayer to play files in the application sandbox, avoiding stuttering due to decoding and resampling when playing large files. (#18538)
1 parent 7f8e050 commit 91ad6da

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

native/cocos/audio/android/AudioPlayerProvider.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
382382
FILE *fp = fopen(audioFilePath.c_str(), "rb");
383383
if (fp != nullptr) {
384384
fseek(fp, 0, SEEK_END);
385+
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY
386+
int fd = fileno(fp);
387+
if (fd > 0) {
388+
assetFd = dup(fd);
389+
}
390+
#endif
385391
fileSize = ftell(fp);
386392
fclose(fp);
387393
} else {
@@ -399,12 +405,6 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
399405
bool AudioPlayerProvider::isSmallFile(const AudioFileInfo &info) { //NOLINT(readability-convert-member-functions-to-static)
400406
//REFINE: If file size is smaller than 100k, we think it's a small file. This value should be set by developers.
401407
auto &audioFileInfo = const_cast<AudioFileInfo &>(info);
402-
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY
403-
if(audioFileInfo.url[0] == '/') {
404-
// avplayer does not support playing audio files in sandbox path currently.
405-
return true;
406-
}
407-
#endif
408408
size_t judgeCount = sizeof(gAudioFileIndicator) / sizeof(gAudioFileIndicator[0]);
409409
size_t pos = audioFileInfo.url.rfind('.');
410410
ccstd::string extension;

native/cocos/audio/openharmony/UrlAudioPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void UrlAudioPlayer::destroy() {
312312
if (!*_isDestroyed) {
313313
*_isDestroyed = true;
314314
OH_AVErrCode code = OH_AVPlayer_Release(_playObj);
315-
if (code == AV_ERR_OK) {
315+
if (code != AV_ERR_OK) {
316316
ALOGE("UrlAudioPlayer release error, code: %d", code);
317317
}
318318
}

0 commit comments

Comments
 (0)