mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge pull request #414 from dumganhar/fix/v1.3-audio-fix
[v1.3] Updates lite audio engine sources from upstream (cocos2d-x).
This commit is contained in:
@@ -134,19 +134,19 @@ bool AudioDecoder::start()
|
||||
do
|
||||
{
|
||||
ret = decodeToPcm();
|
||||
if (!ret)
|
||||
if (!ret)
|
||||
{
|
||||
ALOGE("decodeToPcm (%s) failed!", _url.c_str());
|
||||
break;
|
||||
}
|
||||
ret = resample();
|
||||
if (!ret)
|
||||
if (!ret)
|
||||
{
|
||||
ALOGE("resample (%s) failed!", _url.c_str());
|
||||
break;
|
||||
}
|
||||
ret = interleave();
|
||||
if (!ret)
|
||||
if (!ret)
|
||||
{
|
||||
ALOGE("interleave (%s) failed!", _url.c_str());
|
||||
break;
|
||||
@@ -397,20 +397,20 @@ bool AudioDecoder::decodeToPcm()
|
||||
value = nullptr;
|
||||
valueSize = 0;
|
||||
result = (*mdExtrItf)->GetKeySize(mdExtrItf, i, &keySize);
|
||||
SL_RETURN_VAL_IF_FAILED(result, false, "GetKeySize(%d) failed", i);
|
||||
SL_RETURN_VAL_IF_FAILED(result, false, "GetKeySize(%d) failed", (int)i);
|
||||
|
||||
result = (*mdExtrItf)->GetValueSize(mdExtrItf, i, &valueSize);
|
||||
SL_RETURN_VAL_IF_FAILED(result, false, "GetValueSize(%d) failed", i);
|
||||
SL_RETURN_VAL_IF_FAILED(result, false, "GetValueSize(%d) failed", (int)i);
|
||||
|
||||
keyInfo = (SLMetadataInfo *) malloc(keySize);
|
||||
if (nullptr != keyInfo)
|
||||
{
|
||||
result = (*mdExtrItf)->GetKey(mdExtrItf, i, keySize, keyInfo);
|
||||
|
||||
SL_RETURN_VAL_IF_FAILED(result, false, "GetKey(%d) failed", i);
|
||||
SL_RETURN_VAL_IF_FAILED(result, false, "GetKey(%d) failed", (int)i);
|
||||
|
||||
ALOGV("key[%d] size=%d, name=%s, value size=%d",
|
||||
i, keyInfo->size, keyInfo->data, valueSize);
|
||||
(int)i, (int)keyInfo->size, keyInfo->data, (int)valueSize);
|
||||
/* find out the key index of the metadata we're interested in */
|
||||
if (!strcmp((char *) keyInfo->data, ANDROID_KEY_PCMFORMAT_NUMCHANNELS))
|
||||
{
|
||||
@@ -477,7 +477,7 @@ bool AudioDecoder::decodeToPcm()
|
||||
_result.pcmBuffer->size() / _result.numChannels / (_result.bitsPerSample / 8);
|
||||
|
||||
std::string info = _result.toString();
|
||||
ALOGI("Original audio info: %s, total size: %d", info.c_str(), _result.pcmBuffer->size());
|
||||
ALOGI("Original audio info: %s, total size: %d", info.c_str(), (int)_result.pcmBuffer->size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ bool AudioDecoder::resample()
|
||||
(char *) convert + outputFrames * channels * sizeof(int16_t));
|
||||
_result.pcmBuffer = buffer;
|
||||
|
||||
ALOGV("pcm buffer size: %d", _result.pcmBuffer->size());
|
||||
ALOGV("pcm buffer size: %d", (int)_result.pcmBuffer->size());
|
||||
|
||||
free(convert);
|
||||
free(outputVAddr);
|
||||
@@ -622,7 +622,7 @@ void AudioDecoder::queryAudioInfo()
|
||||
ALOGV("Content duration is unknown (in dec callback)");
|
||||
} else
|
||||
{
|
||||
ALOGV("Content duration is %ums (in dec callback)", durationInMsec);
|
||||
ALOGV("Content duration is %dms (in dec callback)", (int)durationInMsec);
|
||||
_result.duration = durationInMsec / 1000.0f;
|
||||
}
|
||||
|
||||
@@ -727,7 +727,7 @@ void AudioDecoder::decodeToPcmCallback(SLAndroidSimpleBufferQueueItf queueItf)
|
||||
SLmillisecond msec;
|
||||
result = (*_decContext.playItf)->GetPosition(_decContext.playItf, &msec);
|
||||
SL_RETURN_IF_FAILED(result, "%s, GetPosition failed", __FUNCTION__);
|
||||
ALOGV("%s called (iteration %d): current position=%u ms", __FUNCTION__, _counter, msec);
|
||||
ALOGV("%s called (iteration %d): current position=%d ms", __FUNCTION__, _counter, (int)msec);
|
||||
}
|
||||
|
||||
_result.pcmBuffer->insert(_result.pcmBuffer->end(), _decContext.pData,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2014-2015 Chukong Technologies Inc.
|
||||
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -49,7 +49,8 @@
|
||||
#include "audio/android/IAudioPlayer.h"
|
||||
#include "audio/android/ICallerThreadUtils.h"
|
||||
#include "audio/android/AudioPlayerProvider.h"
|
||||
#include "audio/android/cutils/log.h"
|
||||
#include "audio/android/cutils/log.h"
|
||||
#include "audio/android/UrlAudioPlayer.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::experimental;
|
||||
@@ -83,7 +84,7 @@ static CallerThreadUtils __callerThreadUtils;
|
||||
|
||||
static int fdGetter(const std::string& url, off_t* start, off_t* length)
|
||||
{
|
||||
int fd = 0;
|
||||
int fd = -1;
|
||||
if (cocos2d::FileUtilsAndroid::getObbFile() != nullptr)
|
||||
{
|
||||
fd = getObbAssetFileDescriptorJNI(url.c_str(), start, length);
|
||||
@@ -175,19 +176,9 @@ bool AudioEngineImpl::init()
|
||||
|
||||
_audioPlayerProvider = new AudioPlayerProvider(_engineEngine, _outputMixObject, getDeviceSampleRate(), getDeviceAudioBufferSizeInFrames(), fdGetter, &__callerThreadUtils);
|
||||
|
||||
_onPauseListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_COME_TO_BACKGROUND, [this](EventCustom*){
|
||||
if (_audioPlayerProvider != nullptr)
|
||||
{
|
||||
_audioPlayerProvider->pause();
|
||||
}
|
||||
});
|
||||
_onPauseListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_COME_TO_BACKGROUND, CC_CALLBACK_1(AudioEngineImpl::onEnterBackground, this));
|
||||
|
||||
_onResumeListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_COME_TO_FOREGROUND, [this](EventCustom*){
|
||||
if (_audioPlayerProvider != nullptr)
|
||||
{
|
||||
_audioPlayerProvider->resume();
|
||||
}
|
||||
});
|
||||
_onResumeListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_COME_TO_FOREGROUND, CC_CALLBACK_1(AudioEngineImpl::onEnterForeground, this));
|
||||
|
||||
ret = true;
|
||||
}while (false);
|
||||
@@ -195,6 +186,45 @@ bool AudioEngineImpl::init()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AudioEngineImpl::onEnterBackground(EventCustom* event)
|
||||
{
|
||||
// _audioPlayerProvider->pause() pauses AudioMixer and PcmAudioService,
|
||||
// but UrlAudioPlayers could not be paused.
|
||||
if (_audioPlayerProvider != nullptr)
|
||||
{
|
||||
_audioPlayerProvider->pause();
|
||||
}
|
||||
|
||||
// pause UrlAudioPlayers which are playing.
|
||||
for (auto&& e : _audioPlayers)
|
||||
{
|
||||
auto player = e.second;
|
||||
if (dynamic_cast<UrlAudioPlayer*>(player) != nullptr
|
||||
&& player->getState() == IAudioPlayer::State::PLAYING)
|
||||
{
|
||||
_urlAudioPlayersNeedResume.push_back(player);
|
||||
player->pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngineImpl::onEnterForeground(EventCustom* event)
|
||||
{
|
||||
// _audioPlayerProvider->resume() resumes AudioMixer and PcmAudioService,
|
||||
// but UrlAudioPlayers could not be resumed.
|
||||
if (_audioPlayerProvider != nullptr)
|
||||
{
|
||||
_audioPlayerProvider->resume();
|
||||
}
|
||||
|
||||
// resume UrlAudioPlayers
|
||||
for (auto&& player : _urlAudioPlayersNeedResume)
|
||||
{
|
||||
player->resume();
|
||||
}
|
||||
_urlAudioPlayersNeedResume.clear();
|
||||
}
|
||||
|
||||
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
||||
{
|
||||
ALOGV("play2d, _audioPlayers.size=%d", (int)_audioPlayers.size());
|
||||
@@ -219,17 +249,21 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||
|
||||
if (state != IAudioPlayer::State::OVER && state != IAudioPlayer::State::STOPPED)
|
||||
{
|
||||
ALOGV("Ignore state: %d", state);
|
||||
ALOGV("Ignore state: %d", static_cast<int>(state));
|
||||
return;
|
||||
}
|
||||
|
||||
int id = player->getId();
|
||||
|
||||
ALOGV("Removing player id=%d", id);
|
||||
ALOGV("Removing player id=%d, state:%d", id, (int)state);
|
||||
|
||||
auto iter = _callbackMap.find(id);
|
||||
if (iter != _callbackMap.end())
|
||||
{
|
||||
iter->second(id, *AudioEngine::_audioIDInfoMap[id].filePath);
|
||||
if (state == IAudioPlayer::State::OVER)
|
||||
{
|
||||
iter->second(id, *AudioEngine::_audioIDInfoMap[id].filePath);
|
||||
}
|
||||
_callbackMap.erase(iter);
|
||||
}
|
||||
AudioEngine::remove(id);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2014-2015 Chukong Technologies Inc.
|
||||
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -74,6 +74,9 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void onEnterBackground(EventCustom* event);
|
||||
void onEnterForeground(EventCustom* event);
|
||||
|
||||
// engine interfaces
|
||||
SLObjectItf _engineObject;
|
||||
SLEngineItf _engineEngine;
|
||||
@@ -85,6 +88,9 @@ private:
|
||||
std::unordered_map<int, IAudioPlayer*> _audioPlayers;
|
||||
std::unordered_map<int, std::function<void (int, const std::string &)>> _callbackMap;
|
||||
|
||||
// UrlAudioPlayers which need to resumed while entering foreground
|
||||
std::vector<IAudioPlayer*> _urlAudioPlayersNeedResume;
|
||||
|
||||
AudioPlayerProvider* _audioPlayerProvider;
|
||||
EventListener* _onPauseListener;
|
||||
EventListener* _onResumeListener;
|
||||
|
||||
@@ -98,6 +98,9 @@ static void removeItemFromVector(std::vector<T>& v, T item)
|
||||
|
||||
void AudioMixerController::initTrack(Track* track, std::vector<Track*>& tracksToRemove)
|
||||
{
|
||||
if (track->isInitialized())
|
||||
return;
|
||||
|
||||
uint32_t channelMask = audio_channel_out_mask_from_count(2);
|
||||
int32_t name = _mixer->getTrackName(channelMask, AUDIO_FORMAT_PCM_16_BIT,
|
||||
AUDIO_SESSION_OUTPUT_MIX);
|
||||
@@ -133,7 +136,6 @@ void AudioMixerController::initTrack(Track* track, std::vector<Track*>& tracksTo
|
||||
AudioMixer::CHANNEL_MASK,
|
||||
(void *) (uintptr_t) channelMask);
|
||||
|
||||
track->setState(Track::State::PLAYING);
|
||||
track->setName(name);
|
||||
_mixer->enable(name);
|
||||
|
||||
@@ -192,16 +194,9 @@ void AudioMixerController::mixOneFrame()
|
||||
{
|
||||
state = track->getState();
|
||||
|
||||
if (state == Track::State::IDLE)
|
||||
if (state == Track::State::PLAYING)
|
||||
{
|
||||
initTrack(track, tracksToRemove);
|
||||
}
|
||||
else if (state == Track::State::PLAYING)
|
||||
{
|
||||
if (!track->isInitialized())
|
||||
{
|
||||
initTrack(track, tracksToRemove);
|
||||
}
|
||||
|
||||
int name = track->getName();
|
||||
ALOG_ASSERT(name >= 0);
|
||||
@@ -224,10 +219,7 @@ void AudioMixerController::mixOneFrame()
|
||||
}
|
||||
else if (state == Track::State::RESUMED)
|
||||
{
|
||||
if (!track->isInitialized())
|
||||
{
|
||||
initTrack(track, tracksToRemove);
|
||||
}
|
||||
initTrack(track, tracksToRemove);
|
||||
|
||||
if (track->getPrevState() == Track::State::PAUSED)
|
||||
{
|
||||
@@ -241,10 +233,7 @@ void AudioMixerController::mixOneFrame()
|
||||
}
|
||||
else if (state == Track::State::PAUSED)
|
||||
{
|
||||
if (!track->isInitialized())
|
||||
{
|
||||
initTrack(track, tracksToRemove);
|
||||
}
|
||||
initTrack(track, tracksToRemove);
|
||||
|
||||
if (track->getPrevState() == Track::State::PLAYING || track->getPrevState() == Track::State::RESUMED)
|
||||
{
|
||||
@@ -259,14 +248,7 @@ void AudioMixerController::mixOneFrame()
|
||||
{
|
||||
if (track->isInitialized())
|
||||
{
|
||||
if (track->getPrevState() != Track::State::IDLE)
|
||||
{
|
||||
_mixer->deleteTrackName(track->getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGV("Stop track (%p) while it's in IDLE state!", track);
|
||||
}
|
||||
_mixer->deleteTrackName(track->getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
bool init();
|
||||
|
||||
bool addTrack(Track* track);
|
||||
|
||||
bool hasPlayingTacks();
|
||||
|
||||
void pause();
|
||||
|
||||
@@ -48,7 +48,7 @@ static int getSystemAPILevel()
|
||||
return __systemApiLevel;
|
||||
}
|
||||
|
||||
int apiLevel = getSystemProperty("ro.build.version.sdk");
|
||||
int apiLevel = getSDKVersion();
|
||||
if (apiLevel > 0)
|
||||
{
|
||||
ALOGD("Android API level: %d", apiLevel);
|
||||
@@ -210,16 +210,16 @@ void AudioPlayerProvider::preloadEffect(const std::string &audioFilePath, const
|
||||
return;
|
||||
}
|
||||
|
||||
_pcmCacheMutex.lock();
|
||||
auto&& iter = _pcmCache.find(audioFilePath);
|
||||
if (iter != _pcmCache.end())
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(_pcmCacheMutex);
|
||||
auto&& iter = _pcmCache.find(audioFilePath);
|
||||
if (iter != _pcmCache.end())
|
||||
{
|
||||
ALOGV("preload return from cache: (%s)", audioFilePath.c_str());
|
||||
cb(true, iter->second);
|
||||
return;
|
||||
}
|
||||
ALOGV("preload return from cache: (%s)", audioFilePath.c_str());
|
||||
_pcmCacheMutex.unlock();
|
||||
cb(true, iter->second);
|
||||
return;
|
||||
}
|
||||
_pcmCacheMutex.unlock();
|
||||
|
||||
auto info = getFileInfo(audioFilePath);
|
||||
preloadEffect(info, [this, cb, audioFilePath](bool succeed, PcmData data){
|
||||
@@ -246,17 +246,17 @@ void AudioPlayerProvider::preloadEffect(const AudioFileInfo &info, const Preload
|
||||
{
|
||||
std::string audioFilePath = info.url;
|
||||
|
||||
// 1. First time check, if it wasn't in the cache, goto 2 step
|
||||
_pcmCacheMutex.lock();
|
||||
auto&& iter = _pcmCache.find(audioFilePath);
|
||||
if (iter != _pcmCache.end())
|
||||
{
|
||||
// 1. First time check, if it wasn't in the cache, goto 2 step
|
||||
std::lock_guard<std::mutex> lk(_pcmCacheMutex);
|
||||
auto&& iter = _pcmCache.find(audioFilePath);
|
||||
if (iter != _pcmCache.end())
|
||||
{
|
||||
ALOGV("1. Return pcm data from cache, url: %s", info.url.c_str());
|
||||
cb(true, iter->second);
|
||||
return;
|
||||
}
|
||||
ALOGV("1. Return pcm data from cache, url: %s", info.url.c_str());
|
||||
_pcmCacheMutex.unlock();
|
||||
cb(true, iter->second);
|
||||
return;
|
||||
}
|
||||
_pcmCacheMutex.unlock();
|
||||
|
||||
{
|
||||
// 2. Check whether the audio file is being preloaded, if it has been removed from map just now,
|
||||
@@ -273,17 +273,19 @@ void AudioPlayerProvider::preloadEffect(const AudioFileInfo &info, const Preload
|
||||
return;
|
||||
}
|
||||
|
||||
{ // 3. Check it in cache again. If it has been removed from map just now, the file is in
|
||||
// the cache absolutely.
|
||||
std::lock_guard<std::mutex> lk2(_pcmCacheMutex);
|
||||
auto&& iter = _pcmCache.find(audioFilePath);
|
||||
if (iter != _pcmCache.end())
|
||||
{
|
||||
ALOGV("2. Return pcm data from cache, url: %s", info.url.c_str());
|
||||
cb(true, iter->second);
|
||||
return;
|
||||
}
|
||||
// 3. Check it in cache again. If it has been removed from map just now, the file is in
|
||||
// the cache absolutely.
|
||||
_pcmCacheMutex.lock();
|
||||
auto&& iter = _pcmCache.find(audioFilePath);
|
||||
if (iter != _pcmCache.end())
|
||||
{
|
||||
ALOGV("2. Return pcm data from cache, url: %s", info.url.c_str());
|
||||
_pcmCacheMutex.unlock();
|
||||
cb(true, iter->second);
|
||||
return;
|
||||
}
|
||||
_pcmCacheMutex.unlock();
|
||||
|
||||
|
||||
PreloadCallbackParam param;
|
||||
param.callback = cb;
|
||||
@@ -342,7 +344,7 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
|
||||
AudioFileInfo info;
|
||||
long fileSize = 0;
|
||||
off_t start = 0, length = 0;
|
||||
int assetFd = 0;
|
||||
int assetFd = -1;
|
||||
|
||||
if (audioFilePath[0] != '/')
|
||||
{
|
||||
@@ -469,7 +471,7 @@ UrlAudioPlayer *AudioPlayerProvider::createUrlAudioPlayer(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SLuint32 locatorType = info.assetFd > 0 ? SL_DATALOCATOR_ANDROIDFD : SL_DATALOCATOR_URI;
|
||||
SLuint32 locatorType = info.assetFd->getFd() > 0 ? SL_DATALOCATOR_ANDROIDFD : SL_DATALOCATOR_URI;
|
||||
auto urlPlayer = new (std::nothrow) UrlAudioPlayer(_engineItf, _outputMixObject, _callerThreadUtils);
|
||||
bool ret = urlPlayer->prepare(info.url, locatorType, info.assetFd, info.start, info.length);
|
||||
if (!ret)
|
||||
|
||||
@@ -107,14 +107,14 @@ static AudioResampler::src_quality defaultQuality = AudioResampler::DEFAULT_QUAL
|
||||
|
||||
void AudioResampler::init_routine()
|
||||
{
|
||||
int resamplerQuality = getSystemProperty("af.resampler.quality");
|
||||
if (resamplerQuality > 0) {
|
||||
defaultQuality = (src_quality) resamplerQuality;
|
||||
ALOGD("forcing AudioResampler quality to %d", defaultQuality);
|
||||
if (defaultQuality < DEFAULT_QUALITY || defaultQuality > VERY_HIGH_QUALITY) {
|
||||
defaultQuality = DEFAULT_QUALITY;
|
||||
}
|
||||
}
|
||||
// int resamplerQuality = getSystemProperty("af.resampler.quality");
|
||||
// if (resamplerQuality > 0) {
|
||||
// defaultQuality = (src_quality) resamplerQuality;
|
||||
// ALOGD("forcing AudioResampler quality to %d", defaultQuality);
|
||||
// if (defaultQuality < DEFAULT_QUALITY || defaultQuality > VERY_HIGH_QUALITY) {
|
||||
// defaultQuality = DEFAULT_QUALITY;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
uint32_t AudioResampler::qualityMHz(src_quality quality)
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <condition_variable>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
namespace cocos2d { namespace experimental {
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ void PcmAudioPlayer::play()
|
||||
// put track to AudioMixerController
|
||||
ALOGV("PcmAudioPlayer (%p) play (%s) ...", this, _url.c_str());
|
||||
_controller->addTrack(_track);
|
||||
_track->setState(Track::State::PLAYING);
|
||||
}
|
||||
|
||||
void PcmAudioPlayer::pause()
|
||||
|
||||
@@ -169,7 +169,7 @@ void UrlAudioPlayer::stop()
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing or paused, could not invoke stop!", this, _state);
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing or paused, could not invoke stop!", this, static_cast<int>(_state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ void UrlAudioPlayer::pause()
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing, could not invoke pause!", this, _state);
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing, could not invoke pause!", this, static_cast<int>(_state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ void UrlAudioPlayer::resume()
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't paused, could not invoke resume!", this, _state);
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't paused, could not invoke resume!", this, static_cast<int>(_state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ void UrlAudioPlayer::play()
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't paused or initialized, could not invoke play!", this, _state);
|
||||
ALOGW("UrlAudioPlayer (%p, state:%d) isn't paused or initialized, could not invoke play!", this, static_cast<int>(_state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,18 @@ bool UrlAudioPlayer::prepare(const std::string &url, SLuint32 locatorType, std::
|
||||
_url = url;
|
||||
_assetFd = assetFd;
|
||||
|
||||
ALOGV("UrlAudioPlayer::prepare: %s, %d, %d, %d, %d", _url.c_str(), (int)locatorType, assetFd->getFd(), start,
|
||||
const char* locatorTypeStr= "UNKNOWN";
|
||||
if (locatorType == SL_DATALOCATOR_ANDROIDFD)
|
||||
locatorTypeStr = "SL_DATALOCATOR_ANDROIDFD";
|
||||
else if (locatorType == SL_DATALOCATOR_URI)
|
||||
locatorTypeStr = "SL_DATALOCATOR_URI";
|
||||
else
|
||||
{
|
||||
ALOGE("Oops, invalid locatorType: %d", (int)locatorType);
|
||||
return false;
|
||||
}
|
||||
|
||||
ALOGV("UrlAudioPlayer::prepare: %s, %s, %d, %d, %d", _url.c_str(), locatorTypeStr, _assetFd->getFd(), start,
|
||||
length);
|
||||
SLDataSource audioSrc;
|
||||
|
||||
@@ -303,11 +314,6 @@ bool UrlAudioPlayer::prepare(const std::string &url, SLuint32 locatorType, std::
|
||||
audioSrc.pLocator = &locUri;
|
||||
ALOGV("locUri: locatorType: %d", (int)locUri.locatorType);
|
||||
}
|
||||
else
|
||||
{
|
||||
ALOGE("Oops, invalid locatorType: %d", (int)locatorType);
|
||||
return false;
|
||||
}
|
||||
|
||||
// configure audio sink
|
||||
SLDataLocator_OutputMix locOutmix = {SL_DATALOCATOR_OUTPUTMIX, _outputMixObj};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
@@ -48,7 +48,7 @@ AndroidJavaEngine::AndroidJavaEngine()
|
||||
: _implementBaseOnAudioEngine(false)
|
||||
, _effectVolume(1.f)
|
||||
{
|
||||
int sdkVer = getSystemProperty("ro.build.version.sdk");
|
||||
int sdkVer = getSDKVersion();
|
||||
if (sdkVer > 0)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d", "android SDK version:%d", sdkVer);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
||||
@@ -22,27 +22,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "audio/android/utils/Utils.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
|
||||
namespace cocos2d { namespace experimental {
|
||||
|
||||
int getSystemProperty(const std::string& property)
|
||||
int getSDKVersion()
|
||||
{
|
||||
int ret = -1;
|
||||
std::string command = "getprop " + property;
|
||||
FILE* file = popen(command.c_str(), "r");
|
||||
if (file)
|
||||
{
|
||||
char output[100];
|
||||
if (std::fgets(output, sizeof(output), file) != nullptr)
|
||||
ret = std::atoi(output);
|
||||
|
||||
pclose(file);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return JniHelper::callStaticIntMethod("org/cocos2dx/lib/Cocos2dxHelper", "getSDKVersion");
|
||||
}
|
||||
|
||||
}} // end of namespace cocos2d { namespace experimental
|
||||
|
||||
@@ -25,5 +25,5 @@ THE SOFTWARE.
|
||||
#include <string>
|
||||
|
||||
namespace cocos2d { namespace experimental {
|
||||
extern int getSystemProperty(const std::string& property);
|
||||
extern int getSDKVersion();
|
||||
}}
|
||||
|
||||
@@ -663,4 +663,8 @@ public class Cocos2dxHelper {
|
||||
public static float[] getCompassValue() {
|
||||
return Cocos2dxHelper.sCocos2dxAccelerometer.compassFieldValues;
|
||||
}
|
||||
|
||||
public static int getSDKVersion() {
|
||||
return Build.VERSION.SDK_INT;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user