AudioKit on macOS: get/set system device volume - swift

I've used AudioKit.inputDevice, Audiotkit.outputDevice, and friends to get get all input and output devices on my Mac, and to get/set default input and output device.
I wish to read the current volume of these devices, and to be able to set it myself, but I can't find the correct AudioKit API for doing so.
Does anyone know how to do this?

You will want to use a library similar to https://github.com/InerziaSoft/ISSoundAdditions
Changing sound volume becomes as simple as:
[NSSound setSystemVolume:0.5]
--
Duplicate of: Change Volume on Mac programmatically

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 create a global environment variable that can be accessed by SpringBoard or other applications in the jailbroken iPhone?

I found that a variable created in SpringBoard can not be accessed by other regular applications. But now I want to make a flag variable that can share status in the global environment efficiently.
I thought a file created at some path could do that, but that may be not fast enough.
Does any body know how to do this?
You can try combination of a file with notifications of changes in this file. Notifications between processes can be sent in two ways:
Darwin notification center CFNotificationCenterGetDarwinNotifyCenter
Distributed notification center CFNotificationCenterGetDistributedCenter - private API
Distributed notification center is better because you can send notification with some data attached to it. Darwin notification center ignores all user info passed to it. So when you changed some flag and saved it in a file you can send notification with this flag's new value. You don't even need to open file and get flag's value yourself. All other apps just need to listen for this notification.
Here is CFNotificationCenterGetDistributedCenter prototype
CFNotificationCenterRef CFNotificationCenterGetDistributedCenter();
Update:
This function is available in iOS 5.0 and above. If you need to support older versions there are two solutions:
Darwin notification center
CFMessagePort - can transmit arbitary data.
If you really need to support older versions I suggest you using CFMessagePort. It's simple and flexible solution, well documented. If you having troubles with it you can always find working examples.
You can store your var in the keyChain, and make all app which wanna share it in one access group. Hope it help.

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...).

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 ??

Change iPhone volume without user interaction, is it possible?

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.