iosswiftvoiceovermpvolumeview

How to tie Voiceover into an MPVolumeView slider?


I created an MPVolumeView slider in Interface Builder to adjust the audio volume (code below):

import UIKit
import MediaPlayer

class StreamVolumeTableViewCell: AudioStreamTableViewCell {
    static let identifier = "StreamVolumeTableViewCell"


    override func awakeFromNib() {
        super.awakeFromNib()

        self.volumeSlider.setRouteButtonImage(UIImage(named: "black_route_button"), for: .normal)
        self.volumeSlider.showsRouteButton = false
    }

    @IBOutlet var volumeSlider: MPVolumeView!

}

Now I want to make it accessible and tie in Voiceover.

I enabled accessibility on the slider, set its label ("Sound volume."), and set the 'User Interaction Enabled', 'Adjustable', and 'Allows Direct Interaction' traits. When I turn Voiceover on, it speaks the label and default hint, BUT --- when I swipe up and down, the volume slider's value does not change, and I get an error "boop" sound.

How do I accomplish what I'm after?

Thanks!!!


Solution

  • I initially created my volume slider by first inserting a UIView in to my interface using IB, and renaming the class to 'MPVolumeView'. After more reading here, I suspected this is why Voiceover was not getting any of my flicks on the slider it created within the UIView.

    I deleted the UIView and replaced it with a UISlider in IB, and renamed THAT class to 'MPVolumeView'. Now Voiceover responds as expected, getting all my finger flicks to change the slider value, and the volume changes on my device.