How to change ios volume in swift with help UISlider

前端 未结 1 1016
迷失自我
迷失自我 2021-01-17 05:59

I wrote the following code, but it doesn\'t change iOS System Volume, it only changes the sound from within the app. audioPlayer is subclass of AVAudioPla

相关标签:
1条回答
  • 2021-01-17 06:14

    The MPVolumeView class is designed to let you do exactly this. It's in MediaPlayer framework. So, add that to your app to make things build correctly.

    You create it and make it visible the way you instantiate any other subclass of UIView, which you probably know by now.

    You can provide your own frame and use this to change the system volume.

    var wrapperView = UIView(frame: CGRectMake(30, 200, 260, 20))
    self.view.backgroundColor = UIColor.clearColor()
    self.view.addSubview(wrapperView)
    
    // 3
    var volumeView = MPVolumeView(frame: wrapperView.bounds)
    wrapperView.addSubview(volumeView)
    

    For more help you can look here Controlling system volume using swift

    0 讨论(0)
提交回复
热议问题