Playing two mp3s files at the same time?

Hi

Is it possible to play 2 mp3s files at the same time?

I got 2 mp3s files, one for background music and the other is a message I want to play. This works well on the simulator but when ported to a HTC Desire, it only plays the mp3 file that was first called.

I am using
media.playSound('MessageToBePlayed.mp3');
media.playSound('BackgroundMusicToBePlayed.mp3');

I have even converted the 2 files into 1 mp3 file and that also works in the simulator but on the HTC Desire it stops playing after the MessageToBePlayed part has finished!!!

I dont mind if I can get the MessageToBePlayed.mp3 played first and then the BackgroundMusicToBePlayed.mp3 to be played straight after.

Any help or advice would be greatly appreciated.

Thanks in advance

Sai

Play sound can only play 1 sound at a time.

You need to use the new audio.play if you have to play more than 1 sound at a time. The audio.play api's isnt great on android and there are reports of delay before the mp3 plays. I suggest you use audio.play for the background music - where a start delay isn't a major issue and keep using media.play for the message sounds

If you want to play them one after the other with media.playsound, you need to make sure the first ended first, plus about 50ms in my experience.

Hi Kam187

Thank you for your reply.

I have updated the code so that it looks like...

local backgroundMusic = audio.loadSound( "SomeMusic.mp2" )

audio.play(backgroundMusic);
media.playSound('SomeMessage.mp2');

However it is just playing the SomeMessage.mp2 and not any part of SomeMusic.mp2.

Oh, the reason why I call my mp3s mp2s is because I had alot of issues was building with mp3s.

Surely, it cant be that hard to play some back ground music and another sound. Loads of games are like that.

Thanks

Sai

I have a feeling media.play uses channel 1, so you should use channel 2 for audio.play

Do you have any example code of setting the audio.play to channel 2 please?

You can see it here:

http://developer.anscamobile.com/reference/index/audioplay

so just:

audio.play(backgroundMusic, { channel = 2});

Hi

That still didn't work.

I also tried,

local backgroundMusic = audio.loadStream( "SomeMusic.mp2" )
local someMessage = audio.loadStream( "SomeMusic.mp2" )

audio.play(backgroundMusic, { channel = 2});
audio.play(someMessage, { channel = 1});

but that still didn't work.

I also read somewhere that Android needs wav files, but my project don't build at all.

Just an update to everyone.

I have got it working, it plays the message first then plays the background music. I done it by doing...

local stopAfter16Seconds = function()
media.playSound('someMusic.mp2');
end

media.playSound('someMessage.mp2');

timer.performWithDelay( 16000, stopAfter16Seconds )

Note: the message last about 15 seconds, that's why I got the background music to start at 16 seconds.

Its not ideal but it works :)

views:1604 update:2011/10/9 9:57:41
corona forums © 2003-2011