mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10149 from Dhilan007/v3-audioengine-freeze-fix
Fixed AudioEngine causes game 'freeze' on Android
This commit is contained in:
commit
6b5b0f9784
|
@ -24,6 +24,7 @@
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||||
#include "AudioEngine-inl.h"
|
#include "AudioEngine-inl.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
// for native asset manager
|
// for native asset manager
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
|
@ -65,6 +66,7 @@ AudioPlayer::AudioPlayer()
|
||||||
, _duration(0.0f)
|
, _duration(0.0f)
|
||||||
, _playOver(false)
|
, _playOver(false)
|
||||||
, _loop(false)
|
, _loop(false)
|
||||||
|
, _assetFd(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,6 +81,11 @@ AudioPlayer::~AudioPlayer()
|
||||||
_fdPlayerVolume = nullptr;
|
_fdPlayerVolume = nullptr;
|
||||||
_fdPlayerSeek = nullptr;
|
_fdPlayerSeek = nullptr;
|
||||||
}
|
}
|
||||||
|
if(_assetFd > 0)
|
||||||
|
{
|
||||||
|
close(_assetFd);
|
||||||
|
_assetFd = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioPlayer::init(SLEngineItf engineEngine, SLObjectItf outputMixObject,const std::string& fileFullPath, float volume, bool loop)
|
bool AudioPlayer::init(SLEngineItf engineEngine, SLObjectItf outputMixObject,const std::string& fileFullPath, float volume, bool loop)
|
||||||
|
@ -110,15 +117,15 @@ bool AudioPlayer::init(SLEngineItf engineEngine, SLObjectItf outputMixObject,con
|
||||||
|
|
||||||
// open asset as file descriptor
|
// open asset as file descriptor
|
||||||
off_t start, length;
|
off_t start, length;
|
||||||
int fd = AAsset_openFileDescriptor(asset, &start, &length);
|
_assetFd = AAsset_openFileDescriptor(asset, &start, &length);
|
||||||
if (fd <= 0){
|
if (_assetFd <= 0){
|
||||||
AAsset_close(asset);
|
AAsset_close(asset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
AAsset_close(asset);
|
AAsset_close(asset);
|
||||||
|
|
||||||
// configure audio source
|
// configure audio source
|
||||||
loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
|
loc_fd = {SL_DATALOCATOR_ANDROIDFD, _assetFd, start, length};
|
||||||
|
|
||||||
audioSrc.pLocator = &loc_fd;
|
audioSrc.pLocator = &loc_fd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ private:
|
||||||
|
|
||||||
float _duration;
|
float _duration;
|
||||||
int _audioID;
|
int _audioID;
|
||||||
|
int _assetFd;
|
||||||
|
|
||||||
std::function<void (int, const std::string &)> _finishCallback;
|
std::function<void (int, const std::string &)> _finishCallback;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue