Change iPhone volume without user interaction, is it possible? - iphone

I've seen this thread but this is only useful if I wanted the user to pick the volume himself. I wanted my application to change the volume gradually.
Thanks.

You can't. See this thread
You have to remember that the iPhone is designed as phone first and a computer second. Since phones are emergency communication devices whose functioning can literally be a matter of life and death, any programing functionality that might interfere with phone function is restricted. If a program could override the hardware volume settings it could cause a user to miss a critical call with possibly disastrous consequences. No app needs volume control more than users need their phone.
You can always adjust the output of your app's own sound. The AVAudioPlayer for example has a volume setting. You just can't control the volume of the hardware and other apps.

If you are using AVAudioPlayer to play your sounds, you can just set the volume property.
If you are using AudioServicesPlaySystemSound, then you cant.

Related

Mute iPhone programmatically

I have been able to decrease the volume of Ringer by using AVSystemController's setVolume method. However, it doesn't mute the device, there is still 5% volume left. I might need to control the Silent switch but didn't find anything about it.
Please note I don't want answers like The app will be rejected by Apple as I do not intend it to upload.
It is technically possible to change the system volume through the private AVSystemController class in Celestial.framework
Get Framework from here.

How to have sound on objective-c while volume is off

i have to play a sound when an uibutton is clicked. My problem is that when device is with volume down, so user pull down volume in hw way, my sound will have volume down. Is there a possibility to have my sound with max volume though volume is down? I hope my answer is well formed
Whether this is possible or not, it would be a very bad practice. Apps should always respect user's choice, including volume. Think of a user that's using your app in a very quite environment (e.g. hospital, airplane, etc.), so the user turns the volume down - yet your app still makes loud noises. I'm guessing this would rather alienate the user.
My guess is that normally it's not possible though. Have a look at this article: http://developer.apple.com/library/ios/#codinghowtos/AudioAndVideo/_index.html - specifically, look for How do I control playback level? topic.
On iOS you can configure the audio session parameters but there are behaviours that the system will not let you change (when the user receives a call or silences the device for example). The system will send you notifications so you can react gracefully but as others have said, when users silence their device it should be silent, no matter what the developpers want (especially with tons of apps running in the background...).

Best practice for volume control iOS?

Hardware Volume Control
I'm trying to understand what is best practice for apps that are mostly silent but occasionally produce sound. Such apps can take advantage of the side volume control on iOS devices and avoid the need to design in a NSVolume control widget, which I believe is not as convenient as the hardware side volume control. The approach would apply to apps like MapQuest 4 mobile where you get occasional audio prompts that blend well with other music players (using audio ducking) but are silent for the most part. I'm wondering how others are addressing this same issue.
I have developed such a system that works rather nicely. In my approach I query the audio APIs to determine if other music is playing (iPod, AOL Radio, Pandora, etc.) then start an audio session only if no other audio is playing. This ties the hardware side volume control to the app instead of the ringer (for iPhones). The challenge comes when you go to the background. My approach kills (deactivates) the session in the background only if the app is not using audio. If there is audio playing the session is deactivated at the conclusion of the playback.
The idea behind killing the playback is to restore the user's ability to adjust the ringer volume to their liking should my app continue to run in the background.
This question originates from issues I faced when developing the voice navigation feature on MapQuest 4 mobile on iOS in 2008-2009. In this app we wanted the side volume switch to control the volume of the turn advice at all times while the app was running. I later realized that I could not control my ringer volume after arriving at my destination and sending the app to the background. This was years ago but I believe the app was continuing to run in the background which lead to the problem. It is an interesting case, when the user is navigating but sends the app to the background should you continue the audio session? Is is more likely that the user would like to change the app volume or the ringer volume while the app runs in the background?
My general use case (when I posted this question) involved navigating in the background while running another app in the foreground (commonly a music player). However it is also common for the navigation app to be sent to the background while the user sits on the home screen. This is when it would make sense to deactivate the audio session.
It is not as straight forward as it seems but my approach works for most cases. Still I am wondering if there are other more viable solutions to the problem. What are other people doing? Would it make more sense to just include the volume control in a view that auto slides in/out of place? Are there things that I have not considered? How have you approached the problem? Do you have any general suggestions?

system sounds aren't affected by device volume for some users

I have a universal app that uses a combination of SystemSounds and AVAudioPlayer sounds. Everything works fine on all of my devices. However, I've had a couple reports from users that the system sounds play at what seems to be the device's full volume level regardless of the actual volume level set for the device. In other words, pressing the hardware buttons on the side of the device changes the AVAudioPlayer sounds, but the system sounds remain at full volume at all times.
Here's the info I've been able to gather so far:
One of the users' devices is an iPod touch 4th generation and the other is an iPad 2. I don't have access to that iPod model, but I did test with an iPad 2 with no problems. I haven't had reports from iPhone users, so I don't think it's an issue of confusion between the music volume and ringer volume, because these devices don't have a ringer.
I've asked the users to fully quit the app using the task manager, and also to restart their devices, but the problem remained after both of these steps.
I'm initializing an audio session with the MediaPlayback category and with MixWithOthers enabled, to control the AVAudioPlayer sounds. I have another that only uses system sounds and doesn't initialize an audio session, so I asked one of the users to try that app. He reported that the sounds are stuck at full volume with that app, too.
Can anyone suggest why this might be happening? Or is there any further troubleshooting I should ask these users to do, since I can't repeat the problem myself?
Update: Perhaps I could ask users to compare the volume behavior in my apps to the volume in a default Apple app or a simple, free app they could install -- does anyone know of an app that uses system sounds? Then I could at least tell if the problem is specific to my app or general to the device.
"Let me amend something here as I just discovered a new setting that FIXES this problem. Go to settings > sounds > "change with buttons". Turn it on. Problem solved!" # https://discussions.apple.com/thread/2790023?threadID=2790023 ??

Does the iOS let developers do this?

Let's say the user leaves the phone on the table. (probably on home screen)
A few hours later, he picks it up. And when it does, the iPhone detects the accelerometer, and it rings.
Unfortunately, this is not possible. Once the OS goes to the home screen, applications running in the background have a limited set of options.
Read this article for more information: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Not through officially accepted means (i.e. you could do it on a jailbroken phone conceivably). Primarily, you can't run in the background for that purpose. If the app was running in the foreground, you can easily detect motion and perform an activity - but if the phone is left for too long a period without activity, it will sleep.
Unfortunately, the accelerometer is not one of the specified keys in the UIBackgroundModes option in your apps info.plist.
auido, location and voip are the only ones available for now.
short answer: YES
The trick is to make sure the app doesn't get backgrounded when the phone goes to sleep. The other elements like detecting changes in the accelerometer and playing a sound are all standard features.
As for the no sleep solution, it has been asked before, basically is you play a music sample the app will continue running, so perhaps a loop of silence continuously played.
Only if you left an app designed for that purpose running in the foreground.
It won't be possible if your app is running in the background.