1. Load
Cocosdenshion: simpleaudioengine: sharedengine ()-> preloadbackgroundmusic ("music. Mid ");
Cocosdenshion: simpleaudioengine: sharedengine ()-> preloadeffect ("pew-pew-lei.wav ");
These two sentences read the background music files and audio files respectively.
2. Play
Cocosdenshion: simpleaudioengine: sharedengine ()-> playbackgroundmusic ("music. Mid", true );
Cocosdenshion: simpleaudioengine: sharedengine ()-> playeffect ("pew-pew-lei.wav ");
These two sentences are playing music and sound effects respectively.
3. Stop
Cocosdenshion: simpleaudioengine: sharedengine ()-> stopbackgroundmusic (false );
This is to stop playing music.
There are also pause and other related interfaces, but I cannot recover after testing the pause in Win32. I don't know why. You can check the header file of this class by yourself, and there are very few interfaces.
// Pre-load background music
// Cocosdenshion: simpleaudioengine: sharedengine ()-> preloadbackgroundmusic ("kerberhuoworkflow ");
// Play background music
// Cocosdenshion: simpleaudioengine: sharedengine ()-> playbackgroundmusic ("invalid huoworkflow", true );
When the program does not need music, it needs to call simpleaudioengine: sharedengine ()-> end (); release sharedengine ().
Other functions related to Playing Sound Effects
Simpleaudioengine: sharedengine ()-> stopbackgroundmusic (); // stop the background music. A boolean parameter can be used to indicate whether to release the music file.
Simpleaudioengine: sharedengine ()-> pausebackgroundmusic (); // pause background music
Simpleaudioengine: sharedengine ()-> rewindbackgroundmusic (); // call background music again
Simpleaudioengine: sharedengine ()-> isbackgroundmusicplaying () // return the Boolean parameter to check whether background music is playing.
Simpleaudioengine: sharedengine ()-> setbackgroundmusicvolume (0.5); // set the volume to 0.0-1.0 </span>
<Span style = "font-family: Microsoft yahei; font-size: 18px;"> preloadeffect ();
Playeffect ();
Stopeffect (); // stop the sound effect. You can choose to stop a sound effect independently and stop it with the m_nsoundid
Stopalleffects (); // stop all sound effects
Pauseeffect (m_nsoundid); // pause a single sound effect
Resumeeffect (m_nsoundid); // start the sound effect again
Pausealleffects (); // pause all sound effects
Resumealleffects (); // start all sound effects again
Seteffectsvolume (0.5); // sets the sound volume.
Unloadeffect (STD: string (ccfileutils: fullpathfromrelativepath (effect_file). c_str (); // uninstall sound effects </span>
Cocos2dx3.1.1 how to play a sound