Swift: Setting AVAudioSession Output Volume

后端 未结 2 1091
遥遥无期
遥遥无期 2021-01-15 17:25

Is there a way to set the AVAudioSession outputVolume?

    self.audioSession = AVAudioSession.sharedInstance()
    self.audioSession.setActive(true, error: n         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 18:10

    The outputVolume property is read-only. This is due to Apple's conviction that a good user experience will be broken if apps unexpectedly modify sound volume beyond user control.

    From the AVAudioSession docs:

    The system wide output volume can be set directly only by the user; to provide volume control in your app, use the MPVolumeView class

    So this is your only (easy) option...

      MPVolumeView *myVolumeView =
        [[MPVolumeView alloc] initWithFrame:frame];
        [self.view addSubview: myVolumeView];
    

提交回复
热议问题