0

I am on a team in a college course and we're making an iPhone app. We have a shaking functionality in the app that already works. To go with this, we want to be able to have a sound playing and the faster/harder the phone is being shook, the louder the sound will play.

Question: What swift methods (if they're available) can we use to access the user's volume settings? We don't want to change their settings because that would be wrong and likely illegal (very frowned upon at the least). We want to simply see what their volume is set to and set our volume scale to that.

EXAMPLE: Our volume scale has their volume at 50% based on how fast they are shaking. If their settings have the volume at 100 (assuming a volume scale from 0 - 100), our sound would play at sound 50. If their setting were set to 60, our sound would play at 30.

We don't mind reading any articles or tutorials on this, but we haven't been able to find them, so links would be appreciated just as much.

Thanks in advance!

Cody Berry
  • 263
  • 3
  • 14
  • Take a look at `AVAudioPlayer`s `volume` property, provided that's what you are using to play the audio in the first place. – theMikeSwan Apr 02 '18 at 21:37
  • Ah, yes. Thank you! that's exactly what we were looking for. I don't know how we overlooked that. – Cody Berry Apr 02 '18 at 21:40
  • Note that `AVAudioPlayer`'s `volume` property is for the current instance of the player. You will not be able to go beyond the system media volume. So the user-defined system volume is your `1.0` (or 100%). To control system volume, the user can use the slider in `MPVolumeView`. – Alejandro Iván Apr 02 '18 at 21:45
  • The OP says that they want to scale the volume of their audio to the current device volume (i.e. if the device is at 50% volume they want to go from 0%-50%). The `volume` property gives them precisely what they are looking for and saves them any extra math. – theMikeSwan Apr 02 '18 at 22:06

1 Answers1

0

You can add MPVolumeView in your app to allow user control volume setting from your app.

https://github.com/ioscreator/ioscreator/tree/master/IOS8SwiftVolumeTutorial/IOS8SwiftVolumeTutorial

https://www.ioscreator.com/tutorials/volume-view-tutorial-ios8-swift

I am not sure this will help or not.

Get System Volume iOS