Wednesday, July 22, 2015

iOS Tip - Programmatically adjust the device volume

If you want to programmatically adjust the volume of your iOS device, you can make use of the MPVolumeView class. The MPVolumeView is from the MediaPlayer Framework and is a visual control that allows the user to adjust the system audio output volume. However, a lot of times you just want to programatically adjust the volume without user intervention. So how do you do it? The following code snippet shows how this can be done easily!

import MediaPlayer

    let volumeView = MPVolumeView()
    if let view = volumeView.subviews.first as? UISlider{
        view.value0.1 //---0 t0 1.0---

    }

No comments: