Dive into iOS Volume Control

iOS Tech Set
iOS App Development
1 min readMar 17, 2018

Usually, we have two kinds of volume: one is the system audio output volume, which will display when you tap volume up/down buttons on the side of your iPhone; the other one is the volume of a media player, it represents how loud your Netflix movie or favorite song on iTunes is.

In this article we will try to achieve 3 things: hide system volume control, get the value of system volume, and respond to volume change.

Hide System Volume Control

Literately, the way to hide the control is to get it from iOS system and then make it invisible. Here is the sample code to do so:

Please note that we cannot set isHidden of the volumeView to true, otherwise it won’t hide the system volume control. Also, this sample code does not work on simulator but real devices.

Value of the Volume

After iOS 9.0, it is pretty straightforward to fetch the the volume value:

AVAudioSession.sharedInstance().outputVolume

Respond to Volume Change

iOS has an Notification named AVSystemController_SystemVolumeDidChangeNotification for us to track volume change. Here is the sample code in doing so:

Finally, you could reference MPVolumeView official doc for details.

--

--