Ti.Media.Sound.play() no sound on iPhone speaker, works only on headphones

You must Login before you can answer or comment on any questions.

Hi, I got this simple code to play a wave file (downloaded from KitchenSink, so it should work) and the problem is, it works on iPhone/iPad simulator well but when deployed to iPhone 4 the sound is played only when headphones are pluged in. When I unplug it, there is no sound on the phone speaker.

Now I'm sure the file is not corrupted and the path is ok, because on headphones it works, also the phone speaker isn't muted and the volume is 100% (I can hear the 'click' sound on the speare when unlocking the phone).

There is no errors on device logs.

The code is nothing special:

    var player = Ti.Media.createSound({
        url: 'cricket.wav'
    });

    Titanium.API.debug(player.getVolume());
    player.play();

Used versions: iPhone 4 (4.3.5), Titanium SDK: 5.0 xCode: 4.2

3 Answers

Accepted Answer

Titanium.Media.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAYBACK;

Please Add this line just above your line player.play(); and you will get the sound through the speakers and please don't declare the line i wrote globally because if you will do that and if you are recording some sounds also then it will not record because for recording you have to declare like this just before you call start() method of recorder:-

Titanium.Media.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAY_AND_RECORD; please mark the answer as permanent if your problem is resolved

Hi Michal, i tested the code written in kitchen sink app and it works without headphone. so just check for any possible mistake from there.

Well Ishan,

with Ti.Media.AUDIO_SESSION_MODE_PLAYBACK set it works like a charm.

Many thanks.

Your Answer

Think you can help? Login to answer this question!