Skip to content

Add support for avplayer to play files in the application sandbox in openHarmony #4388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v2.4.15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cocos/audio/android/AudioPlayerProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
if (fp != nullptr)
{
fseek(fp, 0, SEEK_END);
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
int fd = fileno(fp);
if (fd > 0)
{
assetFd = dup(fd);
}
#endif
fileSize = ftell(fp);
fclose(fp);
}
Expand All @@ -454,13 +461,6 @@ bool AudioPlayerProvider::isSmallFile(const AudioFileInfo &info)
{
//REFINE: If file size is smaller than 100k, we think it's a small file. This value should be set by developers.
AudioFileInfo &audioFileInfo = const_cast<AudioFileInfo &>(info);

#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
if(audioFileInfo.url[0] == '/') {
// avplayer does not support playing audio files in sandbox path currently.
return true;
}
#endif
size_t judgeCount = sizeof(__audioFileIndicator) / sizeof(__audioFileIndicator[0]);
size_t pos = audioFileInfo.url.rfind(".");
std::string extension;
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/openharmony/UrlAudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void UrlAudioPlayer::destroy()
{
*_isDestroyed = true;
OH_AVErrCode code = OH_AVPlayer_Release(_playObj);
if (code == AV_ERR_OK) {
if (code != AV_ERR_OK) {
ALOGE("UrlAudioPlayer release error, code: %d", code);
}
}
Expand Down