cocos2d-x icon indicating copy to clipboard operation
cocos2d-x copied to clipboard

AudioEngine alSourcePlay error code:a003

Open semgilo opened this issue 7 years ago • 38 comments

  • 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

  1. press home menu to background a while or goto siri
  2. 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

semgilo avatar Feb 22 '17 10:02 semgilo

Thanks for your feedback. Could the test case in cpp-tests/New AudioEngine Test reproduce this issue?

dumganhar avatar Feb 23 '17 02:02 dumganhar

@dumganhar I will give it a try, and then to answer you

semgilo avatar Feb 23 '17 02:02 semgilo

@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 avatar Feb 27 '17 14:02 semgilo

@semgilo, thank you. I will give it a try.

dumganhar avatar Feb 28 '17 01:02 dumganhar

@dumganhar how about the result

semgilo avatar Mar 04 '17 02:03 semgilo

@semgilo , sorry, I'm really busy these days. I will test it when I have time.

dumganhar avatar Mar 06 '17 08:03 dumganhar

@semgilo , I couldn't reproduce by lua-tests/AudioEngineTest. The audio is always playing.

dumganhar avatar Mar 07 '17 02:03 dumganhar

@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 30283beb-8455-4191-835f-6844d5f661ae

semgilo avatar Mar 07 '17 07:03 semgilo

@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 avatar Mar 08 '17 01:03 dumganhar

@dumganhar i upload to youku http://v.youku.com/v_show/id_XMjYxMjIwNjg4MA==.html

semgilo avatar Mar 08 '17 06:03 semgilo

@semgilo , thanks for the video. I will check it again.

dumganhar avatar Mar 09 '17 01:03 dumganhar

@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
}

dumganhar avatar Mar 09 '17 03:03 dumganhar

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.

dumganhar avatar Mar 09 '17 03:03 dumganhar

@semgilo, could my solution work for you?

dumganhar avatar Mar 10 '17 06:03 dumganhar

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 avatar Mar 10 '17 07:03 dumganhar

@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 avatar Mar 10 '17 08:03 semgilo

@semgilo , did you try with lua-tests in v3.14?

dumganhar avatar Mar 10 '17 08:03 dumganhar

@dumganhar yes

semgilo avatar Mar 10 '17 08:03 semgilo

@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.

dumganhar avatar Mar 10 '17 09:03 dumganhar

@semgilo i got the issue when it goto siri 100percent

semgilo avatar Mar 10 '17 09:03 semgilo

Please try to test it according my previous post. It's possible to output some log if it's an issue in SimpleAudioEngine.

dumganhar avatar Mar 10 '17 09:03 dumganhar

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 avatar Mar 10 '17 09:03 semgilo

@semgilo How about the log output after adding #define CD_DEBUG 2?

dumganhar avatar Mar 13 '17 01:03 dumganhar

@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

semgilo avatar Mar 13 '17 03:03 semgilo

I sent another PR (https://github.com/cocos2d/cocos2d-x/pull/17492) to fix A003 error.

dumganhar avatar Mar 14 '17 02:03 dumganhar

@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.

这样,就会导致游戏界面被“卡死”的假象。

重现的步骤跟上文中提到的步骤一样:

  1. Game code only uses AudioEngine interfaces
  2. In AppDelegate.cpp, applicationDidEnterBackground & applicationWillEnterForeground invoke SimpleAudioEngine methods
  3. Launch Lua-tests or your game
  4. Press Home button to switch to background
  5. Click game icon to enter foreground
  6. Long press Home button to call Siri out
  7. Press Home button to go back game again
  8. No sound anymore

唯一特别的地方在第5步foreground之后,在game画面出来,而声音还没正常播放的时候,马上 按第6步操作,就很可能出现这个问题。

ihonk avatar Jun 06 '17 07:06 ihonk

@huangke, thanks for your feedback, I will check it. Reopened this issue.

dumganhar avatar Jun 16 '17 01:06 dumganhar

same issue with itunes, game is paused with message "Audio session is still interrupted, pause director!"

formatCvt avatar Sep 25 '17 13:09 formatCvt

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

formatCvt avatar Sep 25 '17 15:09 formatCvt

any news?

formatCvt avatar Oct 09 '17 12:10 formatCvt