Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play sound on iPhone even in silent mode [duplicate]

I want to make an application which creates sound, music, or system sound when an iPhone is in silent mode. Is it possible to play any type of sound whether music or system tones when it is silent mode?

like image 211
Pankaj Kainthla Avatar asked Sep 18 '10 05:09

Pankaj Kainthla


People also ask

Can I play a sound on someone elses iPhone?

In Find My iPhone on iCloud.com, click All Devices, then select the device you want to play a sound on. If you don't see All Devices, it's because you've already selected a device. Click the name of the current device in the center of the toolbar to access the Devices list, then select a new device. Click Play Sound.

Why does my iPhone still make noise when it's on silent?

Your iPhone's audio system is apparently glitching because it still plays notification sounds even when it's already set to silent. Many people who have encountered the same issue for the first time have found a quick fix by simply switching silent mode off and then on again shortly.

Can iPhone have two audio sources?

You can't play two audio tracks from the same iTunes source or the like but you can connect within apps using “bus” to play along side each other and interact or chain off one another as well.

How do I ping my iPhone from another iPhone?

Open the Find My app. Choose the Devices tab or the Items tab. Select your missing device or item, then choose Play Sound. If your device is offline, it won't play a sound until it connects to a network.


2 Answers

It's not advisable, but who am I to say you can't do it. You may have a good reason to be playing sound.

If you are using Audio Sessions, then include <AVFoundation/AVFoundation.h> at the start of your file and

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

should do the trick. Note if you play music or sounds, then iPod playback will be paused.

Once this has been done, probably somewhere in the initialization of one of your classes that plays the sounds, you can instantiate sounds like this:

// probably an instance variable: AVAudioPlayer *player; NSString *path = [[NSBundle mainBundle] pathForResource...]; NSURL *url = [NSURL fileURLWithPath:path]; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url]; 

When that's done, you can play with it any time you want with:

[player play]; // Play the sound [player pause]; // Pause the sound halfway through playing player.currentTime += 10 // skip forward 10 seconds player.duration // Get the duration 

And other nice stuff. Look up the AVAudioPlayer Class reference.

like image 118
Stone Mason Avatar answered Sep 24 '22 13:09

Stone Mason


And for Swift 2, 3, 4.2

    do {       try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)       try AVAudioSession.sharedInstance().setActive(true)     } catch {       print(error)     } 
like image 29
Tom Avatar answered Sep 24 '22 13:09

Tom