Thursday 13 December 2012

How to Override Silent switch while playing sounds in an iPhone/iPad app using AVPlayer

As you guys know there are 2 ways to play sound files from the within app like game sounds, warning/caution sounds or alarm sounds.

One is by using Audio Services in AudioToolBox frame work.
And the other is by using AVPlayer in AVFoundation frame work.

You can follow How to play sounds in an iPhone/iPad app tutorial to learn how to play sounds in an iOS app.

The trick to override the switch is possible only by using AVPlayer, and here is how we can accomplish that.
Just use the below line, must be used in viewDidLoad or some where before using AVPlayer classes.

[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];

No comments:

Post a Comment