Could not play sound

Topics: Windows Phone 8
Feb 12, 2014 at 9:21 AM
Edited Feb 12, 2014 at 9:49 AM
Hi,
I've made a game using cocos2d xna WP8. I want to add some sounds for my game. But it seems does not work :(

I have a WAV sound file named tingting.xnb (from tingting.wav). Place xnb file into Content\Sound\tingting.xnb, set Build Action = Content, copy to output directory = Copy if newer
public override void ApplicationWillEnterForeground()
        {
            CCDirector.SharedDirector.Resume();

            // if you use SimpleAudioEngine, your background music track must resume here. 
            //CCSimpleAudioEngine.SharedEngine.PauseBackgroundMusic = false;
            CCSimpleAudioEngine.SharedEngine.PreloadBackgroundMusic("Sounds\\tingting"); (DEBUG)

        }
I marked a debug point at DEBUG line, and has a Null Reference Exception occurred maybe file path not found. :( at
m_music = CCContentManager.SharedContentManager.Load<Song>(pFileName);

(CCMusicPlayer.cs)
I am trying many paths for sound file such as: Sounds\tingting.xnb, Content\Sounds\tingting, Content\Sounds\tingting.xnb... but it does not work!

Please expand how to play a sound file in detail :| Thanks so much!
Coordinator
Feb 12, 2014 at 3:37 PM
you need to use the wav file, not the xnb file. Include both in your project and it should work.
Feb 13, 2014 at 1:29 AM
Image

Please review WindowsPhone 8 source code, I tested testWinphone8 project, but sound play does not work!
Coordinator
Feb 13, 2014 at 2:03 AM
The cocosDenshion tests are not maintained so I am not surprised that the wp8 test does not play sound.
Coordinator
Feb 13, 2014 at 2:32 AM
When I run the denshion test in wp8 and try the effect test, I get:

A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.DLL
Unexpected exception while playing a SoundEffect: Sounds/effect1
SharpDX.SharpDXException: HRESULT: [0x88960001], Module: [SharpDX.XAudio2], ApiCode: [XAUDIO2_E_INVALID_CALL/InvalidCall], Message: Unknown
at SharpDX.Result.CheckError()
at SharpDX.XAudio2.SourceVoice.SubmitSourceBuffer(AudioBuffer bufferRef, IntPtr bufferWMARef)


This is the result of the xnb file and not the wav file.
Feb 19, 2014 at 3:53 AM
Edited Feb 19, 2014 at 3:55 AM
I tested the Denshion in wp8, the Background music player worked fine with (wma and xnb files). But the Sound Effect player did not work correctly with xnb file that converted from wma or wav, (same error above). How to play effect?
Coordinator
Feb 19, 2014 at 3:25 PM
On WP8 I only use the raw wav files. I don't use any xnb encoding for sound effects.
Feb 21, 2014 at 2:34 AM
Thanks, it worked fine!
Mar 2, 2014 at 3:57 AM
Edited Mar 2, 2014 at 4:01 AM
What build action, content importer and processor are you using for raw wav files?
I have an issue, some effects works well using compile, mp3 audio file and sound effect, but others not. So maybe the solution you are using can help me with this issue.

The console shows:
Unexpected exception while playing a SoundEffect: audio/menu/transition
System.ObjectDisposedException: This object has already been disposed.
[ObjectDisposed_ObjectName_Name]
Arguments: SoundEffect
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50829.0&File=mscorlib.dll&Key=ObjectDisposed_ObjectName_Name
   at Microsoft.Xna.Framework.Audio.SoundEffect.Play(Single volume, Single pitch, Single pan)
   at Microsoft.Xna.Framework.Audio.SoundEffect.Play()
   at CocosDenshion.CCEffectPlayer.Play(Boolean bLoop)
   at CocosDenshion.CCSimpleAudioEngine.PlayEffect(String pszFilePath, Boolean bLoop)
thanks
Mar 2, 2014 at 4:38 AM
Sorry, the issue was related to CCContentManager unload, i added a clean to the CCSimpleAudioEngine SharedList and all is working right now.
Coordinator
Mar 3, 2014 at 10:52 PM
Did you post a PR back to us? That would help anyone else who might have this problem.