cocos2d-x
cocos2d-x copied to clipboard
AudioEngine alSourcePlay error code:a003
- cocos2d-x version:3.9 (audio had upgrade to 3.15)
- devices test on:iPhone 7
- developing environments
- NDK version:
- Xcode version:8.2
- VS version:
- browser type and version:
Steps to Reproduce:
it can't produce often
- press home menu to background a while or goto siri
- music and sound is disappeared
log: E/AudioPlayer (217): bool cocos2d::experimental::AudioPlayer::play2d():alSourcePlay error code:a003 V/AudioPlayer (69): ~AudioPlayer() (0x11672c250), id=2321 V/AudioPlayer (83): AudioPlayer::destroy begin, id=2321 V/AudioPlayer (128): Before alSourceStop E/AudioPlayer (129): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm destroy 129
V/AudioPlayer (130): Before alSourcei E/AudioPlayer (131): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm destroy 131
V/AudioPlayer (136): AudioPlayer::destroy end, id=2321 V/AudioPlayer (69): ~AudioPlayer() (0x11138a0a0), id=2320 V/AudioPlayer (83): AudioPlayer::destroy begin, id=2320 V/AudioPlayer (128): Before alSourceStop E/AudioPlayer (129): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm destroy 129
V/AudioPlayer (130): Before alSourcei E/AudioPlayer (131): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm destroy 131
V/AudioPlayer (136): AudioPlayer::destroy end, id=2320 V/AudioPlayer (147): AudioPlayer::play2d, _alSource: 2401 E/AudioPlayer (161): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm play2d 161
E/AudioPlayer (162): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm play2d 162
E/AudioPlayer (163): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm play2d 163
E/AudioPlayer (164): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm play2d 164
E/AudioPlayer (208): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm play2d 208
E/AudioPlayer (217): bool cocos2d::experimental::AudioPlayer::play2d():alSourcePlay error code:a003 V/AudioPlayer (69): ~AudioPlayer() (0x1165be510), id=2322 V/AudioPlayer (83): AudioPlayer::destroy begin, id=2322 V/AudioPlayer (128): Before alSourceStop E/AudioPlayer (129): OpenAL error 0xA003 in /Users/semgilo/Documents/SVN/Sanguo/Code/trunk/Client/frameworks/cocos2d-x/cocos/audio/apple/AudioPlayer.mm destroy 129
Thanks for your feedback. Could the test case in cpp-tests/New AudioEngine Test reproduce this issue?
@dumganhar I will give it a try, and then to answer you
@dumganhar it also produced in lua-tests iphone 6 cocos2dx 3.14
hold down the home button utils the siri called, the issue will produced sometime
@semgilo, thank you. I will give it a try.
@dumganhar how about the result
@semgilo , sorry, I'm really busy these days. I will test it when I have time.
@semgilo , I couldn't reproduce by lua-tests/AudioEngineTest. The audio is always playing.
@dumganhar it was reproduced easily , please do it more times
1.open app and play music
2.hold home until siri openned
3.say something
4.hold home return app
i found the other issue : sometime the app crashed when audio uncaching file
i got many crash info
@semgilo , I tried really lots of times without reproducing this issue. Could you upload a video of reproducing? I guess I have something missing.
@dumganhar i upload to youku http://v.youku.com/v_show/id_XMjYxMjIwNjg4MA==.html
@semgilo , thanks for the video. I will check it again.
@semgilo , could you check the AppDelegate.cpp in your game project?
If it has the following SimpleAudioEngine
invocation, try to remove it since you're using AudioEngine and test again.
// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
void AppDelegate::applicationDidEnterBackground()
{
Director::getInstance()->stopAnimation();
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); // Remove this line
// Remove all SimpleAudioEngine invocations
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
Director::getInstance()->startAnimation();
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); // remove this line
// Remove all SimpleAudioEngine invocations
}
It could be reproduced stably by the following steps:
- Game code only uses
AudioEngine
interfaces - In AppDelegate.cpp, applicationDidEnterBackground & applicationWillEnterForeground invoke
SimpleAudioEngine
methods - Launch Lua-tests or your game
- Press Home button to switch to background
- Click game icon to enter foreground
- Long press Home button to call Siri out
- Press Home button to go back game again
- No sound anymore
This issue is caused by using SimpleAudioEngine
and AudioEngine
both.
@semgilo, could my solution work for you?
I sent a PR (https://github.com/cocos2d/cocos2d-x/pull/17485) for this issue to avoid invoking any SimpleAudioEngine methods if game only uses AudioEngine.
@dumganhar it doesn't work for me, i try it by
`// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked. void AppDelegate::applicationDidEnterBackground() { Director::getInstance()->stopAnimation();
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); // Remove this line // Remove all SimpleAudioEngine invocations }
// this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { Director::getInstance()->startAnimation();
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); // remove this line // Remove all SimpleAudioEngine invocations }`
i got the result by the same operation
I/AudioEngine-inl.mm (260): OpenAL was initialized successfully! V/AudioCache (86): AudioCache() 0x15ffd23b8, id=1 V/AudioCache (144): readDataTask, cache id=1 V/AudioCache (196): Orignal total frames: 353664, adjust frames: 529, current total frames: 354193 V/AudioPlayer (147): AudioPlayer::play2d, _alSource: 2400 V/AudioCache (259): pcm buffer was loaded successfully, total frames: 354193, total read frames: 353664, adjust frames: 529, remainingFrames: 529 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003
@semgilo , did you try with lua-tests in v3.14?
@dumganhar yes
@semgilo , could you define CD_DEBUG=2 in cocos/audio/ios/CocosDenshion.h
?
And re-compile and test again?
#undef CD_DEBUG // James: Add this line
#define CD_DEBUG 2 // James: Add this line
#if !defined(CD_DEBUG) || CD_DEBUG == 0
#define CDLOG(...) do {} while (0)
#define CDLOGINFO(...) do {} while (0)
I wanna check it's definitely not caused by SimpleAudioEngine in your environment.
@semgilo i got the issue when it goto siri 100percent
Please try to test it according my previous post. It's possible to output some log if it's an issue in SimpleAudioEngine.
these my modifications AppDelegate.cpp
// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
void AppDelegate::applicationDidEnterBackground()
{
Director::getInstance()->stopAnimation();
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
Director::getInstance()->startAnimation();
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
CocosDenshion.h
#import <OpenAL/al.h>
#import <OpenAL/alc.h>
#import <AudioToolbox/AudioToolbox.h>
#import <Foundation/Foundation.h>
#import "audio/ios/CDConfig.h"
#undef CD_DEBUG // James: Add this line
#define CD_DEBUG 2 // James: Add this line
#if !defined(CD_DEBUG) || CD_DEBUG == 0
#define CDLOG(...) do {} while (0)
#define CDLOGINFO(...) do {} while (0)`
@semgilo
How about the log output after adding #define CD_DEBUG 2
?
@dumganhar @minggo
i don't know the log what you expected i had modified with you posted code the issue still exist and l got the logs
I/AudioEngine-inl.mm (260): OpenAL was initialized successfully! V/AudioCache (86): AudioCache() 0x10ae42748, id=1 V/AudioCache (144): readDataTask, cache id=1 V/AudioCache (196): Orignal total frames: 353664, adjust frames: 529, current total frames: 354193 V/AudioPlayer (147): AudioPlayer::play2d, _alSource: 2400
V/AudioCache (259): pcm buffer was loaded successfully, total frames: 354193, total read frames: 353664, adjust frames: 529, remainingFrames: 529 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a003 E/AudioEngine-inl.mm (491): float cocos2d::experimental::AudioEngineImpl::getCurrentTime(int), audio id:0,error code:a00
I sent another PR (https://github.com/cocos2d/cocos2d-x/pull/17492) to fix A003 error.
@dumganhar 今天我也发现了同样的问题, 我测试环境是
iphone 5S xcode8.0 Coco2dx 3.15 使用的是fix bug之后的代码
比对下面两个日志
正常的日志 I/AudioEngine-inl.mm (314): OpenAL was initialized successfully! D/AudioEngine-inl.mm (147): UIApplicationWillResignActiveNotification D/AudioEngine-inl.mm (157): UIApplicationDidBecomeActiveNotification D/AudioEngine-inl.mm (147): UIApplicationWillResignActiveNotification D/AudioEngine-inl.mm (112): AVAudioSessionInterruptionTypeBegan, application != UIApplicationStateActive, alcMakeContextCurrent(nullptr) D/AudioEngine-inl.mm (157): UIApplicationDidBecomeActiveNotification D/AudioEngine-inl.mm (173): Audio session is still interrupted, pause director! D/AudioEngine-inl.mm (128): AVAudioSessionInterruptionTypeEnded, application == UIApplicationStateActive, alcMakeContextCurrent(s_ALContext) D/AudioEngine-inl.mm (134): AVAudioSessionInterruptionTypeEnded, director was paused, try to resume it.
异常的日志: D/AudioEngine-inl.mm (147): UIApplicationWillResignActiveNotification D/AudioEngine-inl.mm (112): AVAudioSessionInterruptionTypeBegan, application != UIApplicationStateActive, alcMakeContextCurrent(nullptr) D/AudioEngine-inl.mm (112): AVAudioSessionInterruptionTypeBegan, application != UIApplicationStateActive, alcMakeConteD/AudioEngine-inl.mm (157): UIApplicationDidBecomeActiveNotification D/AudioEngine-inl.mm (173): Audio session is still interrupted, pause director!
AVAudioSessionInterruptionTypeEnded没有被系统触发,导致Director被pause
else if (isAudioSessionInterrupted)
{
ALOGD("Audio session is still interrupted, pause director!");
Director::getInstance()->pause();
}
根据ios文档里说明的,AVAudioSessionInterruptionTypeEnded并不一定会被触发 Responding to Interruptions
Note: There is no guarantee that a begin interruption will have a corresponding end interruption. Your app needs to be aware of a switch to a foreground running state or the user pressing a Play button. In either case, determine whether your app should reactivate its audio session.
这样,就会导致游戏界面被“卡死”的假象。
重现的步骤跟上文中提到的步骤一样:
- Game code only uses AudioEngine interfaces
- In AppDelegate.cpp, applicationDidEnterBackground & applicationWillEnterForeground invoke SimpleAudioEngine methods
- Launch Lua-tests or your game
- Press Home button to switch to background
- Click game icon to enter foreground
- Long press Home button to call Siri out
- Press Home button to go back game again
- No sound anymore
唯一特别的地方在第5步foreground之后,在game画面出来,而声音还没正常播放的时候,马上 按第6步操作,就很可能出现这个问题。
@huangke, thanks for your feedback, I will check it. Reopened this issue.
same issue with itunes, game is paused with message "Audio session is still interrupted, pause director!"
https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioGuidelinesByAppType/AudioGuidelinesByAppType.html#//apple_ref/doc/uid/TP40007875-CH11-SW1 looks like AVAudioSessionSilenceSecondaryAudioHint is not implemented
any news?