How to change volume programmatically on iOS 11.4

前端 未结 4 1104
深忆病人
深忆病人 2021-01-17 18:52

Before, I was setting sound volume programmatically using this approach:

MPVolumeView *volumeView = [[MPVolumeView alloc] init];
UISlider *volumeViewSlider =         


        
4条回答
  •  醉梦人生
    2021-01-17 19:47

    I just added the MPVolumeView as a subview to another view (that was never drawn on screen).

    This had to be done prior to any attempt to set or get the volume.

    private let containerView = UIView()
    private let volumeView = MPVolumeView()
    
    func prepareWorkaround() {
        self.containerView.addSubview(self.volumeView)
    }
    

提交回复
热议问题