sound issue : preloadeffect failed

  • MoseHas
    Likes 1

    Problem Description

    Sorry have not solved the last problem and there is another new one incoming.

    Since I was watching the basic lessons about cocos2d-x, I have never succeeded playing any sound effect or music. All I got was exit(0).

     

    First, I could not directly use CocosDenshion in SplashScene. I need to include "SimpleAudioEngine.h"

    Second, I always get unexpectedly quit every time I try to execute my game.

     

     

    Environment: Win 8.1 & MicroSoft Visual Studio 2013 with cocos2d-x-3.6.


  • Sonar Systems admin
    Likes 0

    Does the app work if you don’t have the sound code?


    This reply has been verified.
  • MoseHas
    Likes 1

    Yes it works as long as I comment them. 


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Could you post the code please


    This reply has been verified.
  • MoseHas
    Likes 0

    #include "SplashScene.h"
    #include "MainMenuScene.h"
    #include "Definitions.h"
    #include "SimpleAudioEngine.h"
    
    USING_NS_CC;
    
    Scene* SplashScene::createScene()
    {
        // 'scene' is an autorelease object
        auto scene = Scene::create();
        
        // 'layer' is an autorelease object
        auto layer = SplashScene::create();
    
        // add layer as a child to scene
        scene->addChild(layer);
    
        // return the scene
        return scene;
    }
    
    // on "init" you need to initialize your instance
    bool SplashScene::init()
    {
        //////////////////////////////
        // 1. super init first
        if ( !Layer::init() )
        {
            return false;
        }
        
    	//fail to implement
    	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Sounds/Hit.mp3");
    	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Sounds/Point.mp3");
    	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Sounds/Wing.mp3");
    
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Vec2 origin = Director::getInstance()->getVisibleOrigin();
        
        this->scheduleOnce( schedule_selector( SplashScene::GoToMainMenuScene ), DISPLAY_TIME_SPLASH_SCENE );
    
        auto backgroundSprite = Sprite::create( "Splash Scene.png" );
        backgroundSprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y) );
        
        this->addChild( backgroundSprite );
        
        return true;
    }
    
    void SplashScene::GoToMainMenuScene( float dt )
    {
        auto scene = MainMenuScene::createScene();
        
        Director::getInstance( )->replaceScene( TransitionFade::create( TRANSITION_TIME, scene ) );
    }
    

    Build in success but cannot run it correctly.

    The rest is same as the lesson source code.


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Have you tried a fresh project and seeing if audio playback works?


    This reply has been verified.
  • MoseHas
    Likes 0

    No.

    But I have tried both HelloWorld project and this Flappy Bird project and none of them worked.

    I will try. Hopefully it is not my laptop environment which caused this weird situation.


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    OK try it out and let us know 


    This reply has been verified.
  • MoseHas
    Likes 0

    Sorry that I haven’t replied my latest status.

    Sadly, my whole new project failed to preload audio files.

    So I think it is my problem.

    Apology for bothering, my mistake.


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Keep us informed of how it goes.


    This reply has been verified.
  • MoseHas
    Likes 0

    Hi there.

    I have changed my platform to windows 7 and this is a brand new computer.

    I installed everything including SDK, JDK and so on. Turns out it had no longer crash, but the audio sounds weird.

    Check this out.

    I checked this issue on Google, and others said that this is caused bacause of not preloading sound. But I did preload it in my SplashScene.cpp, even in my AppDelegate.cpp.

    Still did not work.


  • Sonar Systems admin
    Likes 0

    Which part of the audio sounds weird, the flap?


    This reply has been verified.
  • MoseHas
    Likes 0

    Yes, the flapping sound is interrupted by another one if I click too fast.

    I think it should be “whoo, whoo, whoo”, not “wh...wh...wh...whoo”

    Is there any way I can fix it?

  • Sonar Systems admin
    Likes 0

    Can you show the code for playing the flap sound when clicing the screen.


    This reply has been verified.
  • MoseHas
    Likes 0

    First I preload my audio files in my SplashScene.cpp

    bool SplashScene::init()
    {
        //////////////////////////////
        // 1. super init first
        if ( !Layer::init() )
        {
            return false;
        }
        
    	//fail to implement
    	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Sounds/Hit.mp3");
    	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Sounds/Point.mp3");
    	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Sounds/Wing.mp3");
    
    ....
    }

    Hit.mp3 and Point.mp3 are good. I think it is because they only trigger once in several seconds, not like Wing.mp3.

    So I just paste my Wing.mp3 code below.

    in Bird.cpp(I moved it from Bird.h to Bird.cpp)

    void Bird::Fly()
    { 
    	CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sounds/Wing.mp3"); 
    	isFalling = false; 
    }

    That’s all. Do I need to paste the entire code?

  • Sonar Systems admin
    Likes 0

    How long is the wing.mp3 file?


    This reply has been verified.
  • MoseHas
    Likes 0

    Less than 1 second.

  • Sonar Systems admin
    Likes 0

    Do you have a prevention method to not allow the user from tapping the screen multiple times and the bird flying?

  • MoseHas
    Likes 0

    Nope. It is simple. 

    I wonder if it is because my audio has miliseconds silence in the beginning. If I click too fast, it will keep playing the silence part and sounds like totally silent.

  • Sonar Systems admin
    Likes 0

    Try removing the silence


    This reply has been verified.
  • MoseHas
    Likes 0

    This is my original sound wave.

    And this is the edited version.

     

    This is what it sounds like.

     

    Still interrupted by fast clicking, but sounds better.

    I wonder if there is a way to make the audio uninterrupted, making the sound play the whole media and then play the next.


  • Sonar Systems admin
    Likes 0

    Well in flappy bird the time it takes to move the bird is the same length of the duration of the flap sound, you could increase the animation time for the bird moving and prevent the user from clicking when the bird is still moving based on a previous tap.


    This reply has been verified.
  • MoseHas
    Likes 0

    Sounds like a very good method! I will try it.

    Thanks!

Login to reply