Is there a way to play .mp3 files in wp8 cocos2dx?

.mp3 files lead to crash in wp8 and .wav sound files are large enough and thus leads to increase in app size. Till date I haven’t found anything related to this stuff that we can use .mp3 files in a wp8 project.
Any solutions?

1 Like

Windows uses XAudio2 for audio. XAudio2 only supports uncompressed data (PCM). Since mp3 files are compressed, you can’t play them on windows. You could possibliy uncompress them yourself before handing them to XAudio2. Windows Desktop developers have access to Windows Media Foundation that provides these facilities to uncompress sound files.

hmm @miguel12345 thanks

There is a new Audio API coming in the 3.3 release.

ok…that will be great.

@slackmoehrle
Any idea when will the cocos2dx IDE for c++ will come . yet we have xcode , eclipse…but I am waiting for an official coco ide for c++

I dont have an ETA on this. When I know more I’ll communicate it.

You can use Hekkus Sound System to play mp3s. I use it in the Windows Phone version of Geometry Dash and its working perfectly.

http://www.shlzero.com/

2 Likes

Hi Zhenmuron,

can you tell me how to use it? The API documentation is not that good written. Where do i need to place sound files and what to use to play them.

Thanks for your time

1 Like

I tried to use Hekkus too, but when ever I created a sound it was NULL. Perhaps I have the same problem like you lazar89nis. If someone knows how to avoid this, or where to put sound files it would be really helpful.

#include “HSS.h”

hss::Speaker *speaker = 0;

hss::Sound *sound = 0;

hss::Channel *channel = 0;

void main()

{

// create our speaker object

speaker = hss::createSpeaker();

// open the speaker object

speaker->open(44100);

// load our sound

sound = speaker->createSound(“snd.mp3”);

if (sound)

{

// play the sound in the first free channel available, start it paused so we can set the initial position

channel = speaker->playSound(sound, hss::kPlayFree | hss::kPlayPaused);

if (channel)

{

// set position to 2000ms

channel->setPosition(2000, hss::kTimeMilliseconds);

// unpause channel so it starts to play

channel->unpause();

}

}

// When your done

// release sound

if (sound)

sound->release();

// release speaker

speaker->release();

}

5 Likes

Thx Zhenmuron, this really helped. The only thing i had to do is to change
sound = speaker->createSound(“snd.mp3”);
to
sound = speaker->createSound(“Assets/Resources/snd.mp3”);

1 Like

Hi,

could you please explain how you integrated Hekkus into your Project ? I don’t find any .dll or .sln in there :frowning:

You need to download Hekkus and put it in proj.wp8-xaml\packages. There is no .dll or .sln, but you can find .lib.

First you need to add the include directory to the project. Go to the Solution Explorer and right-click on the test project, then select “Properties”. In the left side, under “Configuration properties” expand the “C/C++” node, then select “General”. In the top-right is “Configuration”; change it to “All Configurations”. Then in “Additional Include Directories” add the directory of the static library project where the static library’s header (proj.wp8-xaml\packages\HekkusSoundSystem\include) is at.

Next you need to specify the library to be used. In the project properties, and with the configuration set for All Configurations, go to the “Input” node of the “Linker” properties. In the “Additional Dependencies” add the name of the static library; just the file name and extension, but not the directory (hss.lib).

Then you need to specify the directory of the library. That is done in the project properties, but this time you will specify different directories for each configuration. So with the configuration set for “Active(Debug)”, go to the “General” node of the “Linker” properties. Specify the directory where the Debug configuraton of the library is at. Do the same for the Release configuration.

Then you just #include “hssSpeaker.h” and it should work. :wink:

2 Likes

UPDATE: It work now, I forgot the hss::kPlayPaused not play audio, thanks you again.
Hi, I follow your code, but when debug with Simulator it show on log and no audio, i use latest hekkus lib :

‘TaskHost.exe’ (Win32): Loaded ‘C:\Windows\system32\MMPhoneDeviceApi.dll’. Cannot find or open the PDB file.
‘TaskHost.exe’ (Win32): Loaded ‘C:\Windows\system32\AUDIOSES.DLL’. Cannot find or open the PDB file.
‘TaskHost.exe’ (Win32): Loaded ‘C:\Windows\system32\POWRPROF.DLL’. Cannot find or open the PDB file.
‘TaskHost.exe’ (Win32): Loaded ‘C:\Windows\system32\THREADPOOLWINRT.DLL’. Cannot find or open the PDB file.
‘TaskHost.exe’ (Win32): Loaded ‘C:\Windows\system32\ProcThreadExtHost.dll’. Cannot find or open the PDB file.
The thread 0xff8 has exited with code 0 (0x0).
The thread 0xfe4 has exited with code 0 (0x0).