4

I am using a card reader for iPhone and I need to play a sound while the reader is plugged in. Due to some other issues I used the AudioServicesPlaySystemSound. But the sound is not playing through speaker when the reader is plugged in.

Is there any methods to change the audio channel to speaker while using AudioServicesPlaySystemSound?


UInt32 doChangeDefaultRoute = 1;

AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
                         sizeof (doChangeDefaultRoute),
                         &doChangeDefaultRoute
                         ); 

I have tried the above code. It shows some strange behaviour. I observed the following cases:

  • case 1: Plugged in the reader and tried to play the sound. Failed to play the sound.
  • case 2: Unplugged the reader and played the sound through speaker once. Then plug in the reader and tried to play the same sound. It works!

But I need to play the sound in both cases.

Note: Instead of card reader you can use any device with an audio jack. Even a head set can be used.

includeMe
  • 2,672
  • 3
  • 25
  • 39
arp
  • 41
  • 3

1 Answers1

0

You can try to override sound output to speaker:

UInt32 doChangeDefaultRoute = 1;

AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
                         sizeof (doChangeDefaultRoute),
                         &doChangeDefaultRoute
                         );  
Andrei G.
  • 1,710
  • 1
  • 14
  • 23