Skip to content
Merged
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
3 changes: 2 additions & 1 deletion cocos/audio/android/AudioEngine-inl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ static int fdGetter(const std::string& url, off_t* start, off_t* length)
{
fd = getObbAssetFileDescriptorJNI(url.c_str(), start, length);
}
else

if (fd <= 0)
{
auto asset = AAssetManager_open(cocos2d::FileUtilsAndroid::getAssetManager(), url.c_str(), AASSET_MODE_UNKNOWN);
// open asset as file descriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private MediaPlayer createMediaPlayer(final String path) {
mediaPlayer.setDataSource(fis.getFD());
fis.close();
} else {
if (Cocos2dxHelper.getObbFile() != null) {
if (Cocos2dxHelper.getObbFile() != null && Cocos2dxHelper.getObbFile().getAssetFileDescriptor(path) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to check assetFileDescriptor inside the if sentence.

Copy link
Author

@ghost ghost May 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My purpose is that checking whether the OBB file exists and whether the music file is inside the OBB file. If the music file is not inside the OBB file, we should continue to find it through this.mContext.getAssets().

final AssetFileDescriptor assetFileDescriptor = Cocos2dxHelper.getObbFile().getAssetFileDescriptor(path);
mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
} else {
Expand Down